MDL-29318 login: Handle email in case-insensitive manner
* Let get_complete_user_data() handle the fetching of user data and handle the logic of the errors to be shown based on the exception it throws. This also saves us 1 DB query by eliminating the need to count for the users that match a given email first before fetching user information.
This commit is contained in:
+10
-7
@@ -355,18 +355,21 @@ function core_login_validate_forgot_password_data($data) {
|
||||
if (!validate_email($data['email'])) {
|
||||
$errors['email'] = get_string('invalidemail');
|
||||
|
||||
} else if ($DB->count_records('user', array('email' => $data['email'])) > 1) {
|
||||
$errors['email'] = get_string('forgottenduplicate');
|
||||
|
||||
} else {
|
||||
if ($user = get_complete_user_data('email', $data['email'])) {
|
||||
try {
|
||||
$user = get_complete_user_data('email', $data['email'], null, true);
|
||||
if (empty($user->confirmed)) {
|
||||
send_confirmation_email($user);
|
||||
$errors['email'] = get_string('confirmednot');
|
||||
}
|
||||
}
|
||||
if (!$user and empty($CFG->protectusernames)) {
|
||||
$errors['email'] = get_string('emailnotfound');
|
||||
} catch (dml_missing_record_exception $missingexception) {
|
||||
// User not found. Show error when $CFG->protectusernames is turned off.
|
||||
if (empty($CFG->protectusernames)) {
|
||||
$errors['email'] = get_string('emailnotfound');
|
||||
}
|
||||
} catch (dml_multiple_records_exception $multipleexception) {
|
||||
// Multiple records found. Ask the user to enter a username instead.
|
||||
$errors['email'] = get_string('forgottenduplicate');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user