X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/bce919af7b49bbd06223f79b8c37a53a3d263ff0..8f002227d3beee3921b316db1f6acc5966451f46:/services/userservice.php?ds=inline diff --git a/services/userservice.php b/services/userservice.php index e0b7ba9..44374a0 100644 --- a/services/userservice.php +++ b/services/userservice.php @@ -1,24 +1,25 @@ 'uId', - 'username' => 'username', - 'password' => 'password' - ); - var $profileurl; - var $tablename; - var $sessionkey; - var $cookiekey; - var $cookietime = 1209600; // 2 weeks + return $instance; + } + + var $fields = array( + 'primary' => 'uId', + 'username' => 'username', + 'password' => 'password' + ); + var $profileurl; + var $tablename; + var $sessionkey; + var $cookiekey; + var $cookietime = 1209600; // 2 weeks function UserService(&$db) { $this->db =& $db; @@ -62,6 +63,15 @@ class UserService { return false; } + function _in_regex_array($value, $array) { + foreach ($array as $key => $pattern) { + if (preg_match($pattern, $value)) { + return TRUE; + } + } + return FALSE; + } + function _randompassword() { $password = mt_rand(1, 99999999); $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12)); @@ -324,6 +334,29 @@ class UserService { return false; } + function isBlockedEmail($email) { + // Check whitelist + $whitelist = $GLOBALS['email_whitelist']; + if (!is_null($whitelist) && is_array($whitelist)) { + if (!$this->_in_regex_array($email, $whitelist)) { + // Not in whitelist -> blocked + return TRUE; + } + } + + // Check blacklist + $blacklist = $GLOBALS['email_blacklist']; + if (!is_null($blacklist) && is_array($blacklist)) { + if ($this->_in_regex_array($email, $blacklist)) { + // In blacklist -> blocked + return TRUE; + } + } + + // Not blocked + return FALSE; + } + function isReserved($username) { if (in_array($username, $GLOBALS['reservedusers'])) { return true; @@ -334,7 +367,7 @@ class UserService { function isValidEmail($email) { if (preg_match("/^((?:(?:(?:\w[\.\-\+_]?)*)\w)+)\@((?:(?:(?:\w[\.\-_]?){0,62})\w)+)\.(\w{2,6})$/i", $email) > 0) { - list($emailUser, $emailDomain) = split("@", $email); + list($emailUser, $emailDomain) = explode("@", $email); // Check if the email domain has a DNS record if ($this->_checkdns($emailDomain)) { @@ -357,4 +390,3 @@ class UserService { function getCookieKey() { return $this->cookiekey; } function setCookieKey($value) { $this->cookiekey = $value; } } -?>