Made the check for allowable emails into a new function
This commit is contained in:
@@ -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 /////////////////////////////////////////////
|
||||
|
||||
+2
-23
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-23
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user