Add ChangePassword event
This commit is contained in:
parent
1bace8547b
commit
d6ddb84132
|
@ -483,3 +483,9 @@ CheckPassword: Check a username/password
|
||||||
AutoRegister: Register a new user with the given nickname. Should insert a new User and Profile into the database.
|
AutoRegister: Register a new user with the given nickname. Should insert a new User and Profile into the database.
|
||||||
- $nickname: The nickname to register
|
- $nickname: The nickname to register
|
||||||
|
|
||||||
|
ChangePassword: Handle a password change request
|
||||||
|
- $nickname: user's nickname
|
||||||
|
- $oldpassword: the user's old password
|
||||||
|
- $newpassword: the desired new password
|
||||||
|
- &$errormsg: set this to an error message if the password could not be changed. If the password was changed, leave this as false
|
||||||
|
|
||||||
|
|
|
@ -164,23 +164,32 @@ class PasswordsettingsAction extends AccountSettingsAction
|
||||||
$this->showForm(_('Incorrect old password'));
|
$this->showForm(_('Incorrect old password'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
$oldpassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$original = clone($user);
|
$errormsg = false;
|
||||||
|
if(! Event::handle('ChangePassword', array($user->nickname, $oldpassword, $newpassword, &$errormsg))){
|
||||||
|
//no handler changed the password, so change the password internally
|
||||||
|
$original = clone($user);
|
||||||
|
|
||||||
$user->password = common_munge_password($newpassword, $user->id);
|
$user->password = common_munge_password($newpassword, $user->id);
|
||||||
|
|
||||||
$val = $user->validate();
|
$val = $user->validate();
|
||||||
if ($val !== true) {
|
if ($val !== true) {
|
||||||
$this->showForm(_('Error saving user; invalid.'));
|
$this->showForm(_('Error saving user; invalid.'));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$user->update($original)) {
|
||||||
|
$this->serverError(_('Can\'t save new password.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user->update($original)) {
|
if($errormsg === false)
|
||||||
$this->serverError(_('Can\'t save new password.'));
|
$this->showForm(_('Password saved.'), true);
|
||||||
return;
|
else
|
||||||
}
|
$this->showForm($errormsg);
|
||||||
|
|
||||||
$this->showForm(_('Password saved.'), true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,20 @@ class LdapPlugin extends Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//error_log(print_r($registration_data,1));
|
//set the database saved password to a random string.
|
||||||
|
$registration_data['password']=common_good_rand(16);
|
||||||
$user = User::register($registration_data);
|
$user = User::register($registration_data);
|
||||||
//prevent other handlers from running, as we have registered the user
|
//prevent other handlers from running, as we have registered the user
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onChangePassword($nickname,$oldpassword,$newpassword,&$errormsg)
|
||||||
|
{
|
||||||
|
//TODO implement this
|
||||||
|
$errormsg = _('Sorry, changing LDAP passwords is not supported at this time');
|
||||||
|
|
||||||
|
//return false, indicating that the event has been handled
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user