MDL-52610 user: Honour allowaccountssameemail in create_users ws

Credit to Dmitriy Kuzevanov.
This commit is contained in:
David Monllao
2016-01-12 13:57:33 +08:00
parent d16cdbd81f
commit d95dbc01e2
+2 -1
View File
@@ -180,7 +180,8 @@ class core_user_external extends external_api {
// Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
if (!validate_email($user['email'])) {
throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
} else if ($DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
} else if (empty($CFG->allowaccountssameemail) &&
$DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
}
// End of user info validation.