MDL-49280 user: Config for allowing duplicate emails
authorMichael Aherne <michael.aherne@strath.ac.uk>
Tue, 24 Feb 2015 11:31:04 +0000 (11:31 +0000)
committerMichael Aherne <michael.aherne@strath.ac.uk>
Tue, 4 Aug 2015 07:46:08 +0000 (08:46 +0100)
admin/settings/plugins.php
admin/tool/uploaduser/index.php
admin/tool/uploaduser/user_form.php
lang/en/auth.php
user/edit_form.php
user/editadvanced_form.php

index f311696..9414744 100644 (file)
@@ -80,6 +80,9 @@ if ($hassiteconfig) {
     $temp->add(new admin_setting_heading('manageauthscommonheading', new lang_string('commonsettings', 'admin'), ''));
     $temp->add(new admin_setting_special_registerauth());
     $temp->add(new admin_setting_configcheckbox('authloginviaemail', new lang_string('authloginviaemail', 'core_auth'), new lang_string('authloginviaemail_desc', 'core_auth'), 0));
+    $temp->add(new admin_setting_configcheckbox('allowuserstoshareemailaddresses',
+                    new lang_string('allowuserstoshareemailaddresses', 'core_auth'),
+                    new lang_string('allowuserstoshareemailaddresses_desc', 'core_auth'), 0));
     $temp->add(new admin_setting_configcheckbox('authpreventaccountcreation', new lang_string('authpreventaccountcreation', 'admin'), new lang_string('authpreventaccountcreation_help', 'admin'), 0));
     $temp->add(new admin_setting_configcheckbox('loginpageautofocus', new lang_string('loginpageautofocus', 'admin'), new lang_string('loginpageautofocus_help', 'admin'), 0));
     $temp->add(new admin_setting_configselect('guestloginbutton', new lang_string('guestloginbutton', 'auth'),
index 8d898fd..70ca155 100644 (file)
@@ -168,7 +168,7 @@ if ($formdata = $mform2->is_cancelled()) {
     $allowdeletes      = (!empty($formdata->uuallowdeletes) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC);
     $allowsuspends     = (!empty($formdata->uuallowsuspends));
     $bulk              = $formdata->uubulk;
-    $noemailduplicates = $formdata->uunoemailduplicates;
+    $noemailduplicates = empty($CFG->allowuserstoshareemailaddresses) ? 1 : $formdata->uunoemailduplicates;
     $standardusernames = $formdata->uustandardusernames;
     $resetpasswords    = isset($formdata->uuforcepasswordchange) ? $formdata->uuforcepasswordchange : UU_PWRESET_NONE;
 
index 2e919fd..9a2a33b 100644 (file)
@@ -138,8 +138,13 @@ class admin_uploaduser_form2 extends moodleform {
         $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDNEW);
         $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDINC);
 
-        $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'tool_uploaduser'));
-        $mform->setDefault('uunoemailduplicates', 1);
+        if (!empty($CFG->allowuserstoshareemailaddresses)) {
+            $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'tool_uploaduser'));
+            $mform->setDefault('uunoemailduplicates', 1);
+        } else {
+            $mform->addElement('hidden', 'uunoemailduplicates', 1);
+        }
+        $mform->setType('uunoemailduplicates', PARAM_BOOL);
 
         $mform->addElement('selectyesno', 'uustandardusernames', get_string('uustandardusernames', 'tool_uploaduser'));
         $mform->setDefault('uustandardusernames', 1);
index 68799d5..fb499d9 100644 (file)
@@ -113,6 +113,8 @@ $string['limitconcurrentlogins_desc'] = 'If enabled the number of concurrent bro
 $string['locked'] = 'Locked';
 $string['authloginviaemail'] = 'Allow log in via email';
 $string['authloginviaemail_desc'] = 'Allow users to use both username and email address (if unique) for site login.';
+$string['allowuserstoshareemailaddresses'] = 'Allow users to share email addresses';
+$string['allowuserstoshareemailaddresses_desc'] = 'Allow different user accounts to share the same email address. It is important to ensure that this will not cause any unexpected security issues in your setup before enabling it. For example, password change confirmations will be sent to the shared email address.';
 $string['md5'] = 'MD5 hash';
 $string['nopasswordchange'] = 'Password can not be changed';
 $string['nopasswordchangeforced'] = 'You cannot proceed without changing your password, however there is no available page for changing it. Please contact your Moodle Administrator.';
index 65e8607..fd99788 100644 (file)
@@ -174,7 +174,9 @@ class user_edit_form extends moodleform {
             // Mail not confirmed yet.
         } else if (!validate_email($usernew->email)) {
             $errors['email'] = get_string('invalidemail');
-        } else if (($usernew->email !== $user->email) and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
+        } else if (($usernew->email !== $user->email)
+                and empty($CFG->allowuserstoshareemailaddresses)
+                and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
             $errors['email'] = get_string('emailexists');
         }
 
index ea95370..b58b907 100644 (file)
@@ -262,7 +262,8 @@ class user_editadvanced_form extends moodleform {
         if (!$user or $user->email !== $usernew->email) {
             if (!validate_email($usernew->email)) {
                 $err['email'] = get_string('invalidemail');
-            } else if ($DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
+            } else if (empty($CFG->allowuserstoshareemailaddresses)
+                    and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
                 $err['email'] = get_string('emailexists');
             }
         }