mirror of
https://github.com/typemill/typemill.git
synced 2025-08-06 14:16:46 +02:00
Merge branch 'version143' into develop
This commit is contained in:
@@ -8,10 +8,10 @@ class User extends WriteYaml
|
||||
{
|
||||
$userDir = __DIR__ . '/../../settings/users';
|
||||
|
||||
/* check if plugins directory exists */
|
||||
/* check if users directory exists */
|
||||
if(!is_dir($userDir)){ return array(); }
|
||||
|
||||
/* get all plugins folder */
|
||||
/* get all user files */
|
||||
$users = array_diff(scandir($userDir), array('..', '.'));
|
||||
|
||||
$cleanUser = array();
|
||||
@@ -23,6 +23,43 @@ class User extends WriteYaml
|
||||
|
||||
return $cleanUser;
|
||||
}
|
||||
|
||||
# returns array of emails of all users
|
||||
public function getUserMails()
|
||||
{
|
||||
$userDir = __DIR__ . '/../../settings/users';
|
||||
|
||||
/* check if users directory exists */
|
||||
if(!is_dir($userDir)){ return array(); }
|
||||
|
||||
/* get all user files */
|
||||
$users = array_diff(scandir($userDir), array('..', '.'));
|
||||
|
||||
$usermails = array();
|
||||
|
||||
foreach($users as $key => $user)
|
||||
{
|
||||
if($user == '.logins'){ continue; }
|
||||
|
||||
$contents = file_get_contents($userDir . DIRECTORY_SEPARATOR . $user);
|
||||
|
||||
if($contents === false){ continue; }
|
||||
|
||||
$searchfor = 'email:';
|
||||
|
||||
# escape special characters in the query
|
||||
$pattern = preg_quote($searchfor, '/');
|
||||
|
||||
# finalise the regular expression, matching the whole line
|
||||
$pattern = "/^.*$pattern.*\$/m";
|
||||
|
||||
# search, and store first occurence in $matches
|
||||
if(preg_match($pattern, $contents, $match)){
|
||||
$usermails[] = trim(str_replace("email:", "", $match[0]));
|
||||
}
|
||||
}
|
||||
return $usermails;
|
||||
}
|
||||
|
||||
public function getUser($username)
|
||||
{
|
||||
|
@@ -36,6 +36,26 @@ class Validation
|
||||
return false;
|
||||
}, 'only jpg, jpeg, png, webp, allowed');
|
||||
|
||||
# checks if email is available if user is created
|
||||
Validator::addRule('emailAvailable', function($field, $value, array $params, array $fields) use ($user)
|
||||
{
|
||||
$usermails = $user->getUserMails();
|
||||
if(in_array(trim($value), $usermails)){ return false; }
|
||||
return true;
|
||||
}, 'taken');
|
||||
|
||||
# checks if email is available if userdata is updated
|
||||
Validator::addRule('emailChanged', function($field, $value, array $params, array $fields) use ($user)
|
||||
{
|
||||
$userdata = $user->getSecureUser($fields['username']);
|
||||
if($userdata['email'] == $value){ return true; } # user has not updated his email
|
||||
|
||||
$usermails = $user->getUserMails();
|
||||
if(in_array(trim($value), $usermails)){ return false; }
|
||||
return true;
|
||||
}, 'taken');
|
||||
|
||||
# checks if username is free when create new user
|
||||
Validator::addRule('userAvailable', function($field, $value, array $params, array $fields) use ($user)
|
||||
{
|
||||
$userdata = $user->getUser($value);
|
||||
@@ -43,6 +63,7 @@ class Validation
|
||||
return true;
|
||||
}, 'taken');
|
||||
|
||||
# checks if user exists when userdata is updated
|
||||
Validator::addRule('userExists', function($field, $value, array $params, array $fields) use ($user)
|
||||
{
|
||||
$userdata = $user->getUser($value);
|
||||
@@ -189,6 +210,7 @@ class Validation
|
||||
$v->rule('noHTML', 'lastname')->message(" contains HTML");
|
||||
$v->rule('lengthBetween', 'lastname', 2, 40);
|
||||
$v->rule('email', 'email')->message("e-mail is invalid");
|
||||
$v->rule('emailAvailable', 'email')->message("Email already taken");
|
||||
$v->rule('in', 'userrole', $userroles);
|
||||
|
||||
return $this->validationResult($v);
|
||||
@@ -206,6 +228,7 @@ class Validation
|
||||
$v->rule('noHTML', 'lastname')->message(" contains HTML");
|
||||
$v->rule('lengthBetween', 'lastname', 2, 40);
|
||||
$v->rule('email', 'email')->message("e-mail is invalid");
|
||||
$v->rule('emailChanged', 'email')->message("Email already taken");
|
||||
$v->rule('in', 'userrole', $userroles);
|
||||
|
||||
return $this->validationResult($v);
|
||||
|
Reference in New Issue
Block a user