changedisplayname.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Christopher Schäpers <kondou@ts.unde.re>
  5. * @author David Reagan <reagand@lanecc.edu>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author Lukas Reschke <lukas@owncloud.com>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. // Check if we are a user
  27. OCP\JSON::callCheck();
  28. OC_JSON::checkLoggedIn();
  29. $l = \OC::$server->getL10N('settings');
  30. $username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
  31. $displayName = (string)$_POST["displayName"];
  32. $userstatus = null;
  33. if(OC_User::isAdminUser(OC_User::getUser())) {
  34. $userstatus = 'admin';
  35. }
  36. if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
  37. $userstatus = 'subadmin';
  38. }
  39. if ($username === OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
  40. $userstatus = 'changeOwnDisplayName';
  41. }
  42. if(is_null($userstatus)) {
  43. OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));
  44. exit();
  45. }
  46. // Return Success story
  47. if( OC_User::setDisplayName( $username, $displayName )) {
  48. OC_JSON::success(array("data" => array( "message" => $l->t('Your full name has been changed.'), "username" => $username, 'displayName' => $displayName )));
  49. }
  50. else{
  51. OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change full name"), 'displayName' => OC_User::getDisplayName($username) )));
  52. }