changedisplayname.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // Check if we are a user
  3. OCP\JSON::callCheck();
  4. OC_JSON::checkLoggedIn();
  5. $l=OC_L10N::get('core');
  6. $username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
  7. $displayName = $_POST["displayName"];
  8. $userstatus = null;
  9. if(OC_User::isAdminUser(OC_User::getUser())) {
  10. $userstatus = 'admin';
  11. }
  12. if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
  13. $userstatus = 'subadmin';
  14. }
  15. if ($username === OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
  16. $userstatus = 'changeOwnDisplayName';
  17. }
  18. if(is_null($userstatus)) {
  19. OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));
  20. exit();
  21. }
  22. // Return Success story
  23. if( OC_User::setDisplayName( $username, $displayName )) {
  24. OC_JSON::success(array("data" => array( "message" => $l->t('Your display name has been changed.'), "username" => $username, 'displayName' => $displayName )));
  25. }
  26. else{
  27. OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change display name"), 'displayName' => OC_User::getDisplayName($username) )));
  28. }