nextcloud/settings/ajax/changedisplayname.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2013-02-22 20:21:57 +04:00
<?php
// Check if we are a user
OCP\JSON::callCheck();
OC_JSON::checkLoggedIn();
2014-08-31 12:05:59 +04:00
$l = \OC::$server->getL10N('settings');
2013-02-22 20:21:57 +04:00
$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
$displayName = (string)$_POST["displayName"];
2013-02-22 20:21:57 +04:00
$userstatus = null;
if(OC_User::isAdminUser(OC_User::getUser())) {
$userstatus = 'admin';
}
if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
$userstatus = 'subadmin';
}
2013-04-17 17:32:03 +04:00
if ($username === OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
2013-02-22 20:21:57 +04:00
$userstatus = 'changeOwnDisplayName';
}
if(is_null($userstatus)) {
OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));
exit();
}
// Return Success story
if( OC_User::setDisplayName( $username, $displayName )) {
OC_JSON::success(array("data" => array( "message" => $l->t('Your full name has been changed.'), "username" => $username, 'displayName' => $displayName )));
2013-02-22 20:21:57 +04:00
}
else{
OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change full name"), 'displayName' => OC_User::getDisplayName($username) )));
}