MDL-52610 user: Honour allowaccountssameemail in create_users ws
authorDavid Monllao <davidm@moodle.com>
Wed, 6 Jan 2016 06:41:35 +0000 (14:41 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 12 Jan 2016 05:54:48 +0000 (13:54 +0800)
Credit to Dmitriy Kuzevanov.

user/externallib.php

index e31f488..8ac34aa 100644 (file)
@@ -189,7 +189,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.