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 11:38:03 +01:00
parent 335b6cd060
commit 9d73e7eb1e
6 changed files with 70 additions and 3 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();
@ -21,8 +22,8 @@ if(is_null($userstatus)) {
// 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" => "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>