summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2013-02-06 02:56:01 -0800
committerBjörn Schießle <bjoern@schiessle.org>2013-02-06 02:56:01 -0800
commit2fdf8ff3e7de9a2e7f7d6f895b5c9afbc69b1b75 (patch)
tree07281324bab733309d0965c28edab69f4ddec2df
parent335b6cd0609b269b3b8c85baed2eeed94f654c3d (diff)
parente68d0c7398d49bf3bdc24d8dc8dddb2dd01ac650 (diff)
downloadnextcloud-server-2fdf8ff3e7de9a2e7f7d6f895b5c9afbc69b1b75.tar.gz
nextcloud-server-2fdf8ff3e7de9a2e7f7d6f895b5c9afbc69b1b75.zip
Merge pull request #1490 from schiesbn/user_displayname
let the user change his display name, if supported by the back-end
-rw-r--r--lib/user.php20
-rw-r--r--settings/ajax/changedisplayname.php7
-rw-r--r--settings/css/settings.css2
-rw-r--r--settings/js/personal.js27
-rw-r--r--settings/personal.php2
-rw-r--r--settings/templates/personal.php17
6 files changed, 71 insertions, 4 deletions
diff --git a/lib/user.php b/lib/user.php
index f953d221543..9dc8cca97a6 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -275,7 +275,7 @@ class OC_User {
foreach(self::$_usedBackends as $backend) {
if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
if($backend->userExists($uid)) {
- $success |= $backend->setDisplayName($uid, $displayName);
+ $result |= $backend->setDisplayName($uid, $displayName);
}
}
}
@@ -436,6 +436,24 @@ class OC_User {
}
return false;
}
+
+ /**
+ * @brief Check whether user can change his display name
+ * @param $uid The username
+ * @returns true/false
+ *
+ * Check whether a specified user can change his display name
+ */
+ public static function canUserChangeDisplayName($uid) {
+ foreach(self::$_usedBackends as $backend) {
+ if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
+ if($backend->userExists($uid)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
* @brief Check if the password is correct
diff --git a/settings/ajax/changedisplayname.php b/settings/ajax/changedisplayname.php
index f80ecb7a0c9..8f2ff865bd5 100644
--- a/settings/ajax/changedisplayname.php
+++ b/settings/ajax/changedisplayname.php
@@ -1,5 +1,6 @@
<?php
// Check if we are a user
+
OCP\JSON::callCheck();
OC_JSON::checkLoggedIn();
@@ -15,14 +16,14 @@ if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
}
if(is_null($userstatus)) {
- OC_JSON::error( array( "data" => array( "message" => "Authentication error" )));
+ 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( "username" => $username )));
+ OC_JSON::success(array("data" => array( "username" => $username, 'displayName' => $displayName )));
}
else{
- OC_JSON::error(array("data" => array( "message" => "Unable to change display name" )));
+ OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change display name"), displayName => OC_User::getDisplayName($username) )));
} \ No newline at end of file
diff --git a/settings/css/settings.css b/settings/css/settings.css
index 5a3ab2c6e97..e722cca91ee 100644
--- a/settings/css/settings.css
+++ b/settings/css/settings.css
@@ -8,6 +8,8 @@ input#openid, input#webdav { width:20em; }
/* PERSONAL */
#passworderror { display:none; }
#passwordchanged { display:none; }
+#displaynameerror { display:none; }
+#displaynamechanged { display:none; }
input#identity { width:20em; }
#email { width: 17em; }
diff --git a/settings/js/personal.js b/settings/js/personal.js
index a866e321ad6..d9455b3786b 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -31,6 +31,33 @@ $(document).ready(function(){
}
});
+
+ $("#displaynamebutton").click( function(){
+ if ($('#displayName').val() != '' ) {
+ // Serialize the data
+ var post = $( "#displaynameform" ).serialize();
+ $('#displaynamechanged').hide();
+ $('#displaynemerror').hide();
+ // Ajax foo
+ $.post( 'ajax/changedisplayname.php', post, function(data){
+ if( data.status == "success" ){
+ $('#displaynamechanged').show();
+ }
+ else{
+ $('#newdisplayname').val(data.data.displayName)
+ $('#displaynameerror').html( data.data.message );
+ $('#displaynameerror').show();
+ }
+ });
+ return false;
+ } else {
+ $('#displayName').val($('#oldDisplayName').val());
+ $('#displaynamechanged').hide();
+ $('#displaynameerror').show();
+ return false;
+ }
+
+ });
$('#lostpassword #email').blur(function(event){
if ($(this).val() == this.defaultValue){
diff --git a/settings/personal.php b/settings/personal.php
index a2e510a6d3c..ac2c4704edb 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -48,6 +48,8 @@ $tmpl->assign('usage_relative', $storageInfo['relative']);
$tmpl->assign('email', $email);
$tmpl->assign('languages', $languages);
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
+$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
+$tmpl->assign('displayName', OC_User::getDisplayName());
$forms=OC_App::getForms('personal');
$tmpl->assign('forms', array());
diff --git a/settings/templates/personal.php b/settings/templates/personal.php
index b1cc6713923..0f195d86d3d 100644
--- a/settings/templates/personal.php
+++ b/settings/templates/personal.php
@@ -33,6 +33,23 @@ if($_['passwordChangeSupported']) {
}
?>
+<?php
+if($_['displayNameChangeSupported']) {
+?>
+<form id="displaynameform">
+ <fieldset class="personalblock">
+ <legend><strong><?php echo $l->t('Display Name');?></strong></legend>
+ <div id="displaynamechanged"><?php echo $l->t('Your display name was changed');?></div>
+ <div id="displaynameerror"><?php echo $l->t('Unable to change your display name');?></div>
+ <input type="text" id="displayName" name="displayName" value="<?php echo $_['displayName']?>" />
+ <input type="hidden" id="oldDisplayName" name="oldDisplayName" value="<?php echo $_['displayName']?>" />
+ <input id="displaynamebutton" type="submit" value="<?php echo $l->t('Change display name');?>" />
+ </fieldset>
+</form>
+<?php
+}
+?>
+
<form id="lostpassword">
<fieldset class="personalblock">
<legend><strong><?php echo $l->t('Email');?></strong></legend>