summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-11-05 23:27:18 -0500
committerCraig Andrews <candrews@integralblue.com>2009-11-05 23:27:18 -0500
commitd6ddb84132d7b9510ba82064c67f2a39822dab49 (patch)
treed68d132d685a3694340f249ff427e0bee022aba9
parent1bace8547b0fa3db316ad79e4948869a654b7140 (diff)
Add ChangePassword event
-rw-r--r--EVENTS.txt6
-rw-r--r--actions/passwordsettings.php31
-rw-r--r--plugins/Ldap/LdapPlugin.php12
3 files changed, 37 insertions, 12 deletions
diff --git a/EVENTS.txt b/EVENTS.txt
index c52f0e312..201ce7dfe 100644
--- a/EVENTS.txt
+++ b/EVENTS.txt
@@ -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.
- $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
+
diff --git a/actions/passwordsettings.php b/actions/passwordsettings.php
index cd4beac3f..87eb45a7d 100644
--- a/actions/passwordsettings.php
+++ b/actions/passwordsettings.php
@@ -164,23 +164,32 @@ class PasswordsettingsAction extends AccountSettingsAction
$this->showForm(_('Incorrect old password'));
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();
- if ($val !== true) {
- $this->showForm(_('Error saving user; invalid.'));
- return;
- }
+ $val = $user->validate();
+ if ($val !== true) {
+ $this->showForm(_('Error saving user; invalid.'));
+ return;
+ }
- if (!$user->update($original)) {
- $this->serverError(_('Can\'t save new password.'));
- return;
+ if (!$user->update($original)) {
+ $this->serverError(_('Can\'t save new password.'));
+ return;
+ }
}
- $this->showForm(_('Password saved.'), true);
+ if($errormsg === false)
+ $this->showForm(_('Password saved.'), true);
+ else
+ $this->showForm($errormsg);
}
}
diff --git a/plugins/Ldap/LdapPlugin.php b/plugins/Ldap/LdapPlugin.php
index cabd3c828..755562f54 100644
--- a/plugins/Ldap/LdapPlugin.php
+++ b/plugins/Ldap/LdapPlugin.php
@@ -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);
//prevent other handlers from running, as we have registered the user
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;
+ }
}