Commit ff54be76 authored by Nigel McNie's avatar Nigel McNie

Ensure that the settings screen does not blow up when the user is an SSO user.

Users who do SSO with no parent authority cannot change their password. The form elements to change their password were hidden, but the validate and submit callbacks were not changed to deal with this case, resulting in the settings form crashing on save.
parent c6fb0914
......@@ -147,9 +147,11 @@ $smarty->assign('form', pieform($prefsform));
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords(form, data) {
formSuccess(form, data);
$('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = '';
$('accountprefs_password2').value = '';
if ($('accountprefs_oldpassword')) {
$('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = '';
$('accountprefs_password2').value = '';
}
}");
$smarty->display('account/index.tpl');
......@@ -158,16 +160,18 @@ function accountprefs_validate(Pieform $form, $values) {
$authobj = AuthFactory::create($USER->authinstance);
if ($values['oldpassword'] !== '') {
global $USER, $authtype, $authclass;
if (!$authobj->authenticate_user_account($USER, $values['oldpassword'])) {
$form->set_error('oldpassword', get_string('oldpasswordincorrect', 'account'));
return;
if (isset($values['oldpassword'])) {
if ($values['oldpassword'] !== '') {
global $USER, $authtype, $authclass;
if (!$authobj->authenticate_user_account($USER, $values['oldpassword'])) {
$form->set_error('oldpassword', get_string('oldpasswordincorrect', 'account'));
return;
}
password_validate($form, $values, $USER);
}
else if ($values['password1'] !== '' || $values['password2'] !== '') {
$form->set_error('oldpassword', get_string('mustspecifyoldpassword'));
}
password_validate($form, $values, $USER);
}
else if ($values['password1'] !== '' || $values['password2'] !== '') {
$form->set_error('oldpassword', get_string('mustspecifyoldpassword'));
}
}
......@@ -177,7 +181,7 @@ function accountprefs_submit(Pieform $form, $values) {
$authobj = AuthFactory::create($USER->authinstance);
db_begin();
if ($values['password1'] !== '') {
if (isset($values['password1']) && $values['password1'] !== '') {
global $authclass;
$password = $authobj->change_password($USER, $values['password1']);
$USER->password = $password;
......
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