MDL-46975 core_auth: Make email validation case-insensitive

* Make email query case-insensitive
* Check only for duplicate emails if $CFG->allowaccountssameemail
is empty.
* Compare the values in "Email address" and "Email (again)" in the
signup form in a case-insensitive fashion.
This commit is contained in:
Jun Pataleta
2019-03-29 13:37:07 +08:00
parent 7eb5148264
commit cd69d45d22
+14 -5
View File
@@ -979,15 +979,24 @@ function signup_validate_data($data, $files) {
if (! validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else if ($DB->record_exists('user', array('email' => $data['email']))) {
$errors['email'] = get_string('emailexists') . ' ' .
get_string('emailexistssignuphint', 'moodle',
html_writer::link(new moodle_url('/login/forgot_password.php'), get_string('emailexistshintlink')));
} else if (empty($CFG->allowaccountssameemail)) {
// Make a case-insensitive query for the given email address.
$select = $DB->sql_equal('email', ':email', false) . ' AND mnethostid = :mnethostid';
$params = array(
'email' => $data['email'],
'mnethostid' => $CFG->mnet_localhost_id,
);
// If there are other user(s) that already have the same email, show an error.
if ($DB->record_exists_select('user', $select, $params)) {
$forgotpasswordurl = new moodle_url('/login/forgot_password.php');
$forgotpasswordlink = html_writer::link($forgotpasswordurl, get_string('emailexistshintlink'));
$errors['email'] = get_string('emailexists') . ' ' . get_string('emailexistssignuphint', 'moodle', $forgotpasswordlink);
}
}
if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else if ($data['email2'] != $data['email']) {
} else if (core_text::strtolower($data['email2']) != core_text::strtolower($data['email'])) {
$errors['email2'] = get_string('invalidemail');
}
if (!isset($errors['email'])) {