Commit a8f23f5f authored by Andrew Robert Nicols's avatar Andrew Robert Nicols

Generate an error message if an external auth username is already in use.

If changing authentication method, or authentication username for a user
and that username is already in use within that auth method, Mahara was
hitting an unrecoverable error because of unique constraints in the
database.

Adding this to the validation stage give sa much more appropriate error
message.
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent 83ff8651
......@@ -164,12 +164,25 @@ $siteform = pieform(array(
function edituser_site_validate(Pieform $form, $values) {
global $USER, $SESSION;
if (!$user = get_record('usr', 'id', $values['id'])) {
return false;
}
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
if ($maxquotaenabled && $values['quota'] > $maxquota) {
$form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
$SESSION->add_error_msg(get_string('maxquotaexceeded', 'artefact.file', display_size($maxquota)));
}
// Check that the external username isn't already in use
if ($usedby = get_record_select('auth_remote_user',
'authinstance = ? AND remoteusername = ? AND localusr != ?',
array($values['authinstance'], $values['remoteusername'], $values['id']))
) {
$usedbyuser = get_field('usr', 'username', 'id', $usedby->localusr);
$SESSION->add_error_msg(get_string('duplicateremoteusername', 'auth', $usedbyuser));
$form->set_error('remoteusername', get_string('duplicateremoteusernameformerror', 'auth'));
}
}
function edituser_site_submit(Pieform $form, $values) {
......
......@@ -81,4 +81,8 @@ $string['requiredfieldsset'] = 'Required profile fields set';
$string['noauthpluginconfigoptions'] = 'There are no configuration options associated with this plugin';
$string['hostwwwrootinuse'] = 'WWW root already in use by another institution (%s)';
// Error messages for external authentication usernames
$string['duplicateremoteusername'] = 'This external authentication username is already in use by the user %s. External authentication usernames must be unique within an authentication method.';
$string['duplicateremoteusernameformerror'] = 'External authentication usernames must be unique within an authentication method.';
?>
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