mirror of
https://github.com/moodle/moodle.git
synced 2025-04-07 09:23:31 +02:00
MDL-78888 tool_uploaduser: case-insensitive email matching on upload.
This commit is contained in:
parent
580c009cac
commit
accb66f905
@ -461,9 +461,22 @@ class process {
|
||||
return;
|
||||
}
|
||||
|
||||
$matchparam = $this->get_match_on_email() ? ['email' => $user->email] : ['username' => $user->username];
|
||||
if ($existinguser = $DB->get_records('user', $matchparam + ['mnethostid' => $user->mnethostid])) {
|
||||
if (is_array($existinguser) && count($existinguser) !== 1) {
|
||||
if ($this->get_match_on_email()) {
|
||||
// Case-insensitive query for the given email address.
|
||||
$userselect = $DB->sql_equal('email', ':email', false);
|
||||
$userparams = ['email' => $user->email];
|
||||
} else {
|
||||
$userselect = 'username = :username';
|
||||
$userparams = ['username' => $user->username];
|
||||
}
|
||||
|
||||
// Match the user, also accounting for multiple records by email.
|
||||
$existinguser = $DB->get_records_select('user', "{$userselect} AND mnethostid = :mnethostid",
|
||||
$userparams + ['mnethostid' => $user->mnethostid]);
|
||||
$existingusercount = count($existinguser);
|
||||
|
||||
if ($existingusercount > 0) {
|
||||
if ($existingusercount !== 1) {
|
||||
$this->upt->track('status', get_string('duplicateemail', 'tool_uploaduser', $user->email), 'warning');
|
||||
$this->userserrors++;
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user