]> git.mjollnir.org Git - moodle.git/commitdiff
Made the check for allowable emails into a new function
authormoodler <moodler>
Mon, 6 Sep 2004 15:21:22 +0000 (15:21 +0000)
committermoodler <moodler>
Mon, 6 Sep 2004 15:21:22 +0000 (15:21 +0000)
lib/moodlelib.php
login/signup.php
user/edit.php

index eeaa833889d7c6cc01c85e7dbe12f5df1620d746..373264df56b85016ef6ce51e27c9f5f18f5a2d5f 100644 (file)
@@ -747,6 +747,12 @@ function create_user_record($username, $password, $auth='') {
         }
     }
 
+    if (!empty($newuser->email)) {
+        if (email_is_not_allowed($newuser->email)) {
+            unset($newuser->email);
+        }
+    }
+
     $newuser->auth = (empty($auth)) ? $CFG->auth : $auth;
     $newuser->username = $username;
     $newuser->password = md5($password);
@@ -1640,6 +1646,40 @@ function send_password_change_confirmation_email($user) {
 }
 
 
+function email_is_not_allowed($email) {
+/// Check that an email is allowed.  It returns an error message if there 
+/// was a problem.
+
+    global $CFG;
+
+    if (!empty($CFG->allowemailaddresses)) {
+        $allowed = explode(' ', $CFG->allowemailaddresses);
+        foreach ($allowed as $allowedpattern) {
+            $allowedpattern = trim($allowedpattern);
+            if (!$allowedpattern) {
+                continue;
+            }
+            if (strpos($email, $allowedpattern) !== false) {  // Match!
+                return false;
+            }
+        }
+        return get_string("emailonlyallowed", '', $CFG->allowemailaddresses);
+
+    } else if (!empty($CFG->denyemailaddresses)) {
+        $denied = explode(' ', $CFG->denyemailaddresses);
+        foreach ($denied as $deniedpattern) {
+            $deniedpattern = trim($deniedpattern);
+            if (!$deniedpattern) {
+                continue;
+            }
+            if (strpos($email, $deniedpattern) !== false) {   // Match!
+                return get_string("emailnotallowed", '', $CFG->denyemailaddresses);
+            }
+        }
+    }
+
+    return false;
+}
 
 
 /// FILE HANDLING  /////////////////////////////////////////////
index ba48373a70ecb335f0fce9e1953726a4d35d6c65..5b06e1bce0cb8d4817adacee7ade12a3aa3b3550 100644 (file)
@@ -147,29 +147,8 @@ function validate_form($user, &$err) {
     }
 
     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);
-                }
-            }
+        if ($error = email_is_not_allowed($user->email)) {
+            $err->email = $error;
         }
     }
 
index 4a1db9b6645d3f7af1e01d549f8bde039ebe5ee3..6c9ace70712cd914305191e5d8ded3b9e4bcbc6e 100644 (file)
@@ -256,29 +256,8 @@ function find_form_errors(&$user, &$usernew, &$err) {
     }
     
     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);
-                }
-            }
+        if ($error = email_is_not_allowed($usernew->email)) {
+            $err["email"] = $error;
         }
     }