]> git.mjollnir.org Git - moodle.git/commitdiff
Two new config variables allow certain email addresses to be allowed or not.
authormoodler <moodler>
Mon, 6 Sep 2004 04:38:40 +0000 (04:38 +0000)
committermoodler <moodler>
Mon, 6 Sep 2004 04:38:40 +0000 (04:38 +0000)
config-dist.php
lang/en/moodle.php
login/signup.php
user/edit.php

index e04401e8c78ff7fa0ec77cc0a9a38a73b363d20a..985025803bba428b2d8841e022ace823de025a2f 100644 (file)
@@ -181,6 +181,13 @@ $CFG->defaultblocks = 'participants,activity_modules,search_forums,admin,course_
 // Seconds for files to remain in caches. Decrease this if you are worried
 // about students being served outdated versions of uploaded files.
 //      $CFG->filelifetime = 86400;
+// 
+// The following two settings allow you to specify allowed domains for 
+// email addresses.  If the first one is set, then Moodle will DISALLOW
+// all domains EXCEPT those listed.  Otherwise, if the second one is set
+// then all addresses are ALLOWED EXCEPT those listed.
+//      $CFG->allowemailaddresses = "myschool.edu.au hotmail.com";
+//      $CFG->denyemailaddresses = "hotmail.com yahoo.com";
 
 //=========================================================================
 // ALL DONE!  To continue installation, visit your main page with a browser
index c8158c176c35e02dbc6235e7ede76ce53f123301..ca6481a985fb275b9ccfa5fb8eebccbca3f8466e 100644 (file)
@@ -372,6 +372,8 @@ $string['emailenableclick'] = 'Click here to re-enable all email being sent to t
 $string['emailexists'] = 'This email address is already registered.';
 $string['emailformat'] = 'Email format';
 $string['emailmustbereal'] = 'Note: your email address must be a real one';
+$string['emailnotallowed'] = 'Email addresses in these domains are not allowed ($a)';
+$string['emailonlyallowed'] = 'This email is not one of those that are allowed ($a)';
 $string['emailpasswordconfirmation'] = 'Hi $a->firstname,
 
 Someone (probably you) has requested a new password for your
@@ -992,9 +994,12 @@ $string['updatingain'] = 'Updating $a->what in $a->in';
 $string['upload'] = 'Upload';
 $string['uploadafile'] = 'Upload a file';
 $string['uploadedfileto'] = 'Uploaded $a->file to $a->directory';
+$string['uploadformlimit'] = 'Uploaded file exceeded the maximum size limit set by the form';
 $string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?';
 $string['uploadnotallowed'] = 'Uploads are not allowed';
+$string['uploadpartialfile'] = 'File was only partially uploaded';
 $string['uploadproblem'] = 'An unknown problem occurred while uploading the file \'$a\' (perhaps it was too large?)';
+$string['uploadserverlimit'] = 'Uploaded file exceeded the maximum size limit set by the server';
 $string['uploadthisfile'] = 'Upload this file';
 $string['uploadusers'] = 'Upload users';
 $string['usedinnplaces'] = 'Used in $a places';
index 6385bd35af7e1b19193e58bb4cbc659383b94f0c..ba48373a70ecb335f0fce9e1953726a4d35d6c65 100644 (file)
@@ -146,6 +146,33 @@ function validate_form($user, &$err) {
         $err->country = get_string("missingcountry");
     }
 
+    if (empty($err->email)) {
+        if (!empty($CFG->allowemailaddresses)) {
+            $allowed = explode(' ', $CFG->allowemailaddresses);
+            $err->email = get_string("emailonlyallowed", '', $CFG->allowemailaddresses);   // Default
+            foreach ($allowed as $allowedpattern) {
+                $allowedpattern = trim($allowedpattern);
+                if (!$allowedpattern) {
+                    continue;
+                }
+                if (strpos($user->email, $allowedpattern) !== false) {
+                    unset($err->email);
+                }
+            }
+        } else if (!empty($CFG->denyemailaddresses)) {
+            $denied = explode(' ', $CFG->denyemailaddresses);
+            foreach ($denied as $deniedpattern) {
+                $deniedpattern = trim($deniedpattern);
+                if (!$deniedpattern) {
+                    continue;
+                }
+                if (strpos($user->email, $deniedpattern) !== false) {
+                    $err->email = get_string("emailnotallowed", '', $CFG->denyemailaddresses);
+                }
+            }
+        }
+    }
+
     return;
 }
 
index 96e6c76c417b671e3f8e0275949faa632c9004c4..4a1db9b6645d3f7af1e01d549f8bde039ebe5ee3 100644 (file)
@@ -246,14 +246,41 @@ function find_form_errors(&$user, &$usernew, &$err) {
     if (empty($usernew->country))
         $err["country"] = get_string("missingcountry");
 
-    if (! validate_email($usernew->email))
+    if (! validate_email($usernew->email)) {
         $err["email"] = get_string("invalidemail");
 
-    else if ($otheruser = get_record("user", "email", $usernew->email)) {
+    else if ($otheruser = get_record("user", "email", $usernew->email)) {
         if ($otheruser->id <> $user->id) {
             $err["email"] = get_string("emailexists");
         }
     }
+    
+    if (empty($err["email"]) and !isadmin()) {
+        if (!empty($CFG->allowemailaddresses)) {
+            $allowed = explode(' ', $CFG->allowemailaddresses);
+            $err["email"] = get_string("emailonlyallowed", '', $CFG->allowemailaddresses);   // Default
+            foreach ($allowed as $allowedpattern) {
+                $allowedpattern = trim($allowedpattern);
+                if (!$allowedpattern) {
+                    continue;
+                }
+                if (strpos($usernew->email, $allowedpattern) !== false) {
+                    unset($err["email"]);
+                }
+            }
+        } else if (!empty($CFG->denyemailaddresses)) {
+            $denied = explode(' ', $CFG->denyemailaddresses);
+            foreach ($denied as $deniedpattern) {
+                $deniedpattern = trim($deniedpattern);
+                if (!$deniedpattern) {
+                    continue;
+                }
+                if (strpos($usernew->email, $deniedpattern) !== false) {
+                    $err->email = get_string("emailnotallowed", '', $CFG->denyemailaddresses);
+                }
+            }
+        }
+    }
 
     $user->email = $usernew->email;