MDL-64950 core: Handle username in a case-insensitive fashion

This commit is contained in:
Jun Pataleta
2019-03-06 12:45:27 +08:00
parent e1d6600fbe
commit 313f2be603
+14 -1
View File
@@ -4769,9 +4769,22 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
return false;
}
// Change the field to lowercase.
$field = core_text::strtolower($field);
// List of case insensitive fields.
$caseinsensitivefields = ['username'];
// Build the WHERE clause for an SQL query.
$params = array('fieldval' => $value);
$constraints = "$field = :fieldval AND deleted <> 1";
// Do a case-insensitive query, if necessary.
if (in_array($field, $caseinsensitivefields)) {
$fieldselect = $DB->sql_equal($field, ':fieldval', false);
} else {
$fieldselect = "$field = :fieldval";
}
$constraints = "$fieldselect AND deleted <> 1";
// If we are loading user data based on anything other than id,
// we must also restrict our search based on mnet host.