Commit 74e5f9e1 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Put repeated reset password code in one place



Change-Id: I83c4ba70d69724bca120bbd757732fb34a23192e
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 1a2b377a
......@@ -350,18 +350,7 @@ function adduser_submit(Pieform $form, $values) {
}
}
// Add salt and encrypt the pw, if the auth instance allows for it
$userobj = new User();
$userobj = $userobj->find_by_id($user->id);
$authobj = AuthFactory::create($user->authinstance);
if (method_exists($authobj, 'change_password')) {
$authobj->change_password($userobj, $user->password);
} else {
$userobj->password = '';
$userobj->salt = auth_get_random_salt();
$userobj->commit();
}
unset($userobj, $authobj);
reset_password($user);
$SESSION->add_ok_msg(get_string('newusercreated', 'admin'));
redirect('/admin/users/edit.php?id=' . $user->id);
......
......@@ -368,17 +368,7 @@ function finish_import() {
}
foreach ($ADDEDUSERS as $user) {
// Add salt and encrypt the pw, if the auth instance allows for it
$userobj = new User();
$userobj = $userobj->find_by_id($user->id);
$authobj = AuthFactory::create($user->authinstance);
if (method_exists($authobj, 'change_password')) {
$authobj->change_password($userobj, $user->password);
} else {
$userobj->password = '';
$userobj->salt = auth_get_random_salt();
$userobj->commit();
}
reset_password($user);
}
if (!empty($FAILEDUSERS)) {
......
......@@ -382,19 +382,8 @@ function uploadcsv_submit(Pieform $form, $values) {
}
foreach ($addedusers as $user) {
// Add salt and encrypt the pw, if the auth instance allows for it
$userobj = new User();
$userobj = $userobj->find_by_id($user->id);
$authobj_tmp = AuthFactory::create($user->authinstance);
if (method_exists($authobj_tmp, 'change_password')) {
$authobj_tmp->change_password($userobj, $user->password, false);
} else {
$userobj->password = '';
$userobj->salt = auth_get_random_salt();
$userobj->commit();
}
reset_password($user, false);
}
unset($authobj_tmp, $userobj);
log_info('Inserted ' . count($CSVDATA) . ' records');
......
......@@ -1622,6 +1622,21 @@ function auth_get_random_salt() {
return substr(md5(rand(1000000, 9999999)), 2, 8);
}
// Add salt and encrypt the pw for a user, if their auth instance allows for it
function reset_password($user, $resetpasswordchange=true) {
$userobj = new User();
$userobj->find_by_id($user->id);
$authobj = AuthFactory::create($user->authinstance);
if (method_exists($authobj, 'change_password')) {
$authobj->change_password($userobj, $user->password, $resetpasswordchange);
}
else {
$userobj->password = '';
$userobj->salt = auth_get_random_salt();
$userobj->commit();
}
}
class PluginAuth extends Plugin {
public static function get_event_subscriptions() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment