Merge pull request #1490 from schiesbn/user_displayname

let the user change his display name, if supported by the back-end
This commit is contained in:
Björn Schießle 2013-02-06 02:56:01 -08:00
commit 2fdf8ff3e7
6 changed files with 71 additions and 4 deletions

View File

@ -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

View File

@ -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) )));
}

View File

@ -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; }

View File

@ -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){

View File

@ -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());

View File

@ -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>