@@ -20,13 +20,19 @@ discard block |
||
20 | 20 | |
21 | 21 | # Validate values |
22 | 22 | |
23 | - if (false === ($email = Validate::userEmail($email))) return 'USER_ERROR_EMAIL_INVALID'; |
|
23 | + if (false === ($email = Validate::userEmail($email))) { |
|
24 | + return 'USER_ERROR_EMAIL_INVALID'; |
|
25 | + } |
|
24 | 26 | |
25 | 27 | # Check email exists |
26 | 28 | |
27 | - if (false === ($check_email = Auth::user()->check('email', $email))) return 'USER_ERROR_EDIT_PERSONAL'; |
|
29 | + if (false === ($check_email = Auth::user()->check('email', $email))) { |
|
30 | + return 'USER_ERROR_EDIT_PERSONAL'; |
|
31 | + } |
|
28 | 32 | |
29 | - if ($check_email === 1) return 'USER_ERROR_EMAIL_DUPLICATE'; |
|
33 | + if ($check_email === 1) { |
|
34 | + return 'USER_ERROR_EMAIL_DUPLICATE'; |
|
35 | + } |
|
30 | 36 | |
31 | 37 | # Update user |
32 | 38 | |
@@ -40,7 +46,9 @@ discard block |
||
40 | 46 | $data['country'] = $country; |
41 | 47 | $data['timezone'] = $timezone; |
42 | 48 | |
43 | - if (!Auth::user()->edit($data)) return 'USER_ERROR_EDIT_PERSONAL'; |
|
49 | + if (!Auth::user()->edit($data)) { |
|
50 | + return 'USER_ERROR_EDIT_PERSONAL'; |
|
51 | + } |
|
44 | 52 | |
45 | 53 | # ------------------------ |
46 | 54 |
@@ -20,17 +20,25 @@ discard block |
||
20 | 20 | |
21 | 21 | # Validate values |
22 | 22 | |
23 | - if (false === ($password = Validate::userPassword($password))) return 'USER_ERROR_PASSWORD_INVALID'; |
|
23 | + if (false === ($password = Validate::userPassword($password))) { |
|
24 | + return 'USER_ERROR_PASSWORD_INVALID'; |
|
25 | + } |
|
24 | 26 | |
25 | - if (false === ($password_new = Validate::userPassword($password_new))) return 'USER_ERROR_PASSWORD_NEW_INVALID'; |
|
27 | + if (false === ($password_new = Validate::userPassword($password_new))) { |
|
28 | + return 'USER_ERROR_PASSWORD_NEW_INVALID'; |
|
29 | + } |
|
26 | 30 | |
27 | - if (0 !== strcmp($password_new, $password_retype)) return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
31 | + if (0 !== strcmp($password_new, $password_retype)) { |
|
32 | + return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
33 | + } |
|
28 | 34 | |
29 | 35 | # Check password |
30 | 36 | |
31 | 37 | $password = Str::encode(Auth::user()->auth_key, $password); |
32 | 38 | |
33 | - if (0 !== strcmp(Auth::user()->password, $password)) return 'USER_ERROR_PASSWORD_INCORRECT'; |
|
39 | + if (0 !== strcmp(Auth::user()->password, $password)) { |
|
40 | + return 'USER_ERROR_PASSWORD_INCORRECT'; |
|
41 | + } |
|
34 | 42 | |
35 | 43 | # Encode password |
36 | 44 | |
@@ -43,7 +51,9 @@ discard block |
||
43 | 51 | $data['auth_key'] = $auth_key; |
44 | 52 | $data['password'] = $password; |
45 | 53 | |
46 | - if (!Auth::user()->edit($data)) return 'USER_ERROR_EDIT_PASSWORD'; |
|
54 | + if (!Auth::user()->edit($data)) { |
|
55 | + return 'USER_ERROR_EDIT_PASSWORD'; |
|
56 | + } |
|
47 | 57 | |
48 | 58 | # ------------------------ |
49 | 59 |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | |
11 | 11 | public function __invoke(array $post) { |
12 | 12 | |
13 | - if (Auth::check()) return true; |
|
13 | + if (Auth::check()) { |
|
14 | + return true; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | # Declare variables |
16 | 18 | |
@@ -22,15 +24,25 @@ discard block |
||
22 | 24 | |
23 | 25 | # Validate values |
24 | 26 | |
25 | - if (false === ($name = Validate::userName($name))) return 'USER_ERROR_NAME_INVALID'; |
|
27 | + if (false === ($name = Validate::userName($name))) { |
|
28 | + return 'USER_ERROR_NAME_INVALID'; |
|
29 | + } |
|
26 | 30 | |
27 | - if (false === ($password = Validate::userPassword($password))) return 'USER_ERROR_PASSWORD_INVALID'; |
|
31 | + if (false === ($password = Validate::userPassword($password))) { |
|
32 | + return 'USER_ERROR_PASSWORD_INVALID'; |
|
33 | + } |
|
28 | 34 | |
29 | - if (false === ($email = Validate::userEmail($email))) return 'USER_ERROR_EMAIL_INVALID'; |
|
35 | + if (false === ($email = Validate::userEmail($email))) { |
|
36 | + return 'USER_ERROR_EMAIL_INVALID'; |
|
37 | + } |
|
30 | 38 | |
31 | - if (0 !== strcmp($password, $password_retype)) return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
39 | + if (0 !== strcmp($password, $password_retype)) { |
|
40 | + return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
41 | + } |
|
32 | 42 | |
33 | - if (false === Security::checkCaptcha($captcha)) return 'USER_ERROR_CAPTCHA_INCORRECT'; |
|
43 | + if (false === Security::checkCaptcha($captcha)) { |
|
44 | + return 'USER_ERROR_CAPTCHA_INCORRECT'; |
|
45 | + } |
|
34 | 46 | |
35 | 47 | # Create user object |
36 | 48 | |
@@ -38,15 +50,23 @@ discard block |
||
38 | 50 | |
39 | 51 | # Check name exists |
40 | 52 | |
41 | - if (false === ($check_name = $user->check('name', $name))) return 'USER_ERROR_AUTH_REGISTER'; |
|
53 | + if (false === ($check_name = $user->check('name', $name))) { |
|
54 | + return 'USER_ERROR_AUTH_REGISTER'; |
|
55 | + } |
|
42 | 56 | |
43 | - if ($check_name === 1) return 'USER_ERROR_NAME_DUPLICATE'; |
|
57 | + if ($check_name === 1) { |
|
58 | + return 'USER_ERROR_NAME_DUPLICATE'; |
|
59 | + } |
|
44 | 60 | |
45 | 61 | # Check email exists |
46 | 62 | |
47 | - if (false === ($check_email = $user->check('email', $email))) return 'USER_ERROR_AUTH_REGISTER'; |
|
63 | + if (false === ($check_email = $user->check('email', $email))) { |
|
64 | + return 'USER_ERROR_AUTH_REGISTER'; |
|
65 | + } |
|
48 | 66 | |
49 | - if ($check_email === 1) return 'USER_ERROR_EMAIL_DUPLICATE'; |
|
67 | + if ($check_email === 1) { |
|
68 | + return 'USER_ERROR_EMAIL_DUPLICATE'; |
|
69 | + } |
|
50 | 70 | |
51 | 71 | # Encode password |
52 | 72 | |
@@ -69,7 +89,9 @@ discard block |
||
69 | 89 | $data['time_registered'] = REQUEST_TIME; |
70 | 90 | $data['time_logged'] = REQUEST_TIME; |
71 | 91 | |
72 | - if (!$user->create($data)) return 'USER_ERROR_AUTH_REGISTER'; |
|
92 | + if (!$user->create($data)) { |
|
93 | + return 'USER_ERROR_AUTH_REGISTER'; |
|
94 | + } |
|
73 | 95 | |
74 | 96 | # Send mail |
75 | 97 |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | |
11 | 11 | public function __invoke(array $post) { |
12 | 12 | |
13 | - if (!Auth::check()) return false; |
|
13 | + if (!Auth::check()) { |
|
14 | + return false; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | # Declare variables |
16 | 18 | |
@@ -22,9 +24,13 @@ discard block |
||
22 | 24 | |
23 | 25 | # Validate values |
24 | 26 | |
25 | - if (false === ($password_new = Validate::userPassword($password_new))) return 'USER_ERROR_PASSWORD_NEW_INVALID'; |
|
27 | + if (false === ($password_new = Validate::userPassword($password_new))) { |
|
28 | + return 'USER_ERROR_PASSWORD_NEW_INVALID'; |
|
29 | + } |
|
26 | 30 | |
27 | - if (0 !== strcmp($password_new, $password_retype)) return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
31 | + if (0 !== strcmp($password_new, $password_retype)) { |
|
32 | + return 'USER_ERROR_PASSWORD_MISMATCH'; |
|
33 | + } |
|
28 | 34 | |
29 | 35 | # Encode password |
30 | 36 | |
@@ -34,7 +40,9 @@ discard block |
||
34 | 40 | |
35 | 41 | $data = ['auth_key' => $auth_key, 'password' => $password]; |
36 | 42 | |
37 | - if (!Auth::user()->edit($data)) return 'USER_ERROR_AUTH_RECOVER'; |
|
43 | + if (!Auth::user()->edit($data)) { |
|
44 | + return 'USER_ERROR_AUTH_RECOVER'; |
|
45 | + } |
|
38 | 46 | |
39 | 47 | # Remove secret |
40 | 48 |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | |
11 | 11 | public function __invoke(array $post) { |
12 | 12 | |
13 | - if (Auth::check()) return true; |
|
13 | + if (Auth::check()) { |
|
14 | + return true; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | # Declare variables |
16 | 18 | |
@@ -22,9 +24,13 @@ discard block |
||
22 | 24 | |
23 | 25 | # Validate values |
24 | 26 | |
25 | - if (false === ($name = Validate::userName($name))) return 'USER_ERROR_NAME_INVALID'; |
|
27 | + if (false === ($name = Validate::userName($name))) { |
|
28 | + return 'USER_ERROR_NAME_INVALID'; |
|
29 | + } |
|
26 | 30 | |
27 | - if (false === Security::checkCaptcha($captcha)) return 'USER_ERROR_CAPTCHA_INCORRECT'; |
|
31 | + if (false === Security::checkCaptcha($captcha)) { |
|
32 | + return 'USER_ERROR_CAPTCHA_INCORRECT'; |
|
33 | + } |
|
28 | 34 | |
29 | 35 | # Create user object |
30 | 36 | |
@@ -32,13 +38,19 @@ discard block |
||
32 | 38 | |
33 | 39 | # Init user |
34 | 40 | |
35 | - if (!$user->init($name, 'name')) return 'USER_ERROR_NAME_INCORRECT'; |
|
41 | + if (!$user->init($name, 'name')) { |
|
42 | + return 'USER_ERROR_NAME_INCORRECT'; |
|
43 | + } |
|
36 | 44 | |
37 | - if (Auth::admin() && ($user->rank < RANK_ADMINISTRATOR)) return 'USER_ERROR_NAME_INCORRECT'; |
|
45 | + if (Auth::admin() && ($user->rank < RANK_ADMINISTRATOR)) { |
|
46 | + return 'USER_ERROR_NAME_INCORRECT'; |
|
47 | + } |
|
38 | 48 | |
39 | 49 | # Check access |
40 | 50 | |
41 | - if (!Auth::admin() && ($user->rank === RANK_GUEST)) return 'USER_ERROR_ACCESS'; |
|
51 | + if (!Auth::admin() && ($user->rank === RANK_GUEST)) { |
|
52 | + return 'USER_ERROR_ACCESS'; |
|
53 | + } |
|
42 | 54 | |
43 | 55 | # Create session |
44 | 56 | |
@@ -48,7 +60,9 @@ discard block |
||
48 | 60 | |
49 | 61 | $data = ['id' => $user->id, 'code' => $code, 'ip' => $ip, 'time' => $time]; |
50 | 62 | |
51 | - if (!$secret->create($data)) return 'USER_ERROR_AUTH_RESET'; |
|
63 | + if (!$secret->create($data)) { |
|
64 | + return 'USER_ERROR_AUTH_RESET'; |
|
65 | + } |
|
52 | 66 | |
53 | 67 | # Send mail |
54 | 68 |
@@ -10,7 +10,9 @@ discard block |
||
10 | 10 | |
11 | 11 | public function __invoke(array $post) { |
12 | 12 | |
13 | - if (Auth::check()) return true; |
|
13 | + if (Auth::check()) { |
|
14 | + return true; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | # Declare variables |
16 | 18 | |
@@ -22,9 +24,13 @@ discard block |
||
22 | 24 | |
23 | 25 | # Validate values |
24 | 26 | |
25 | - if (false === ($name = Validate::userName($name))) return 'USER_ERROR_NAME_INVALID'; |
|
27 | + if (false === ($name = Validate::userName($name))) { |
|
28 | + return 'USER_ERROR_NAME_INVALID'; |
|
29 | + } |
|
26 | 30 | |
27 | - if (false === ($password = Validate::userPassword($password))) return 'USER_ERROR_PASSWORD_INVALID'; |
|
31 | + if (false === ($password = Validate::userPassword($password))) { |
|
32 | + return 'USER_ERROR_PASSWORD_INVALID'; |
|
33 | + } |
|
28 | 34 | |
29 | 35 | # Create user object |
30 | 36 | |
@@ -32,19 +38,27 @@ discard block |
||
32 | 38 | |
33 | 39 | # Init user |
34 | 40 | |
35 | - if (!$user->init($name, 'name')) return 'USER_ERROR_NAME_INCORRECT'; |
|
41 | + if (!$user->init($name, 'name')) { |
|
42 | + return 'USER_ERROR_NAME_INCORRECT'; |
|
43 | + } |
|
36 | 44 | |
37 | - if (Auth::admin() && ($user->rank < RANK_ADMINISTRATOR)) return 'USER_ERROR_NAME_INCORRECT'; |
|
45 | + if (Auth::admin() && ($user->rank < RANK_ADMINISTRATOR)) { |
|
46 | + return 'USER_ERROR_NAME_INCORRECT'; |
|
47 | + } |
|
38 | 48 | |
39 | 49 | # Check password |
40 | 50 | |
41 | 51 | $password = Str::encode($user->auth_key, $password); |
42 | 52 | |
43 | - if (0 !== strcmp($user->password, $password)) return 'USER_ERROR_PASSWORD_INCORRECT'; |
|
53 | + if (0 !== strcmp($user->password, $password)) { |
|
54 | + return 'USER_ERROR_PASSWORD_INCORRECT'; |
|
55 | + } |
|
44 | 56 | |
45 | 57 | # Check access |
46 | 58 | |
47 | - if (!Auth::admin() && ($user->rank === RANK_GUEST)) return 'USER_ERROR_ACCESS'; |
|
59 | + if (!Auth::admin() && ($user->rank === RANK_GUEST)) { |
|
60 | + return 'USER_ERROR_ACCESS'; |
|
61 | + } |
|
48 | 62 | |
49 | 63 | # Create session |
50 | 64 | |
@@ -54,7 +68,9 @@ discard block |
||
54 | 68 | |
55 | 69 | $data = ['id' => $user->id, 'code' => $code, 'ip' => $ip, 'time' => $time]; |
56 | 70 | |
57 | - if (!$session->create($data)) return 'USER_ERROR_AUTH_LOGIN'; |
|
71 | + if (!$session->create($data)) { |
|
72 | + return 'USER_ERROR_AUTH_LOGIN'; |
|
73 | + } |
|
58 | 74 | |
59 | 75 | # Set session variable |
60 | 76 |
@@ -12,9 +12,13 @@ discard block |
||
12 | 12 | |
13 | 13 | private static function getAuth(string $code, string $type, int $lifetime) { |
14 | 14 | |
15 | - if (!($auth = Entitizer::get($type))->init($code, 'code')) return false; |
|
15 | + if (!($auth = Entitizer::get($type))->init($code, 'code')) { |
|
16 | + return false; |
|
17 | + } |
|
16 | 18 | |
17 | - if (($auth->ip !== REQUEST_CLIENT_IP) || ($auth->time < (REQUEST_TIME - $lifetime))) return false; |
|
19 | + if (($auth->ip !== REQUEST_CLIENT_IP) || ($auth->time < (REQUEST_TIME - $lifetime))) { |
|
20 | + return false; |
|
21 | + } |
|
18 | 22 | |
19 | 23 | # ------------------------ |
20 | 24 | |
@@ -25,9 +29,13 @@ discard block |
||
25 | 29 | |
26 | 30 | private static function getUser(int $id) { |
27 | 31 | |
28 | - if (0 === ($user = Entitizer::get(ENTITY_TYPE_USER, $id))->id) return false; |
|
32 | + if (0 === ($user = Entitizer::get(ENTITY_TYPE_USER, $id))->id) { |
|
33 | + return false; |
|
34 | + } |
|
29 | 35 | |
30 | - if ($user->rank < (self::$admin ? RANK_ADMINISTRATOR : RANK_USER)) return false; |
|
36 | + if ($user->rank < (self::$admin ? RANK_ADMINISTRATOR : RANK_USER)) { |
|
37 | + return false; |
|
38 | + } |
|
31 | 39 | |
32 | 40 | # ------------------------ |
33 | 41 | |
@@ -42,17 +50,23 @@ discard block |
||
42 | 50 | |
43 | 51 | # Check session code |
44 | 52 | |
45 | - if (false === ($code = Validate::authCode(Session::get('code')))) return false; |
|
53 | + if (false === ($code = Validate::authCode(Session::get('code')))) { |
|
54 | + return false; |
|
55 | + } |
|
46 | 56 | |
47 | 57 | # Get auth |
48 | 58 | |
49 | 59 | $type = ENTITY_TYPE_USER_SESSION; $lifetime = CONFIG_USER_SESSION_LIFETIME; |
50 | 60 | |
51 | - if (false === ($session = self::getAuth($code, $type, $lifetime))) return false; |
|
61 | + if (false === ($session = self::getAuth($code, $type, $lifetime))) { |
|
62 | + return false; |
|
63 | + } |
|
52 | 64 | |
53 | 65 | # Get user |
54 | 66 | |
55 | - if (false === ($user = self::getUser($session->id))) return false; |
|
67 | + if (false === ($user = self::getUser($session->id))) { |
|
68 | + return false; |
|
69 | + } |
|
56 | 70 | |
57 | 71 | # Update session |
58 | 72 | |
@@ -71,21 +85,29 @@ discard block |
||
71 | 85 | |
72 | 86 | public static function secret() { |
73 | 87 | |
74 | - if ((null === self::$user) || (0 !== self::$user->id)) return false; |
|
88 | + if ((null === self::$user) || (0 !== self::$user->id)) { |
|
89 | + return false; |
|
90 | + } |
|
75 | 91 | |
76 | 92 | # Check secret code |
77 | 93 | |
78 | - if (false === ($code = Validate::authCode(Request::get('code')))) return false; |
|
94 | + if (false === ($code = Validate::authCode(Request::get('code')))) { |
|
95 | + return false; |
|
96 | + } |
|
79 | 97 | |
80 | 98 | # Get auth |
81 | 99 | |
82 | 100 | $type = ENTITY_TYPE_USER_SECRET; $lifetime = CONFIG_USER_SECRET_LIFETIME; |
83 | 101 | |
84 | - if (false === ($secret = self::getAuth($code, $type, $lifetime))) return false; |
|
102 | + if (false === ($secret = self::getAuth($code, $type, $lifetime))) { |
|
103 | + return false; |
|
104 | + } |
|
85 | 105 | |
86 | 106 | # Get user |
87 | 107 | |
88 | - if (false === ($user = self::getUser($secret->id))) return false; |
|
108 | + if (false === ($user = self::getUser($secret->id))) { |
|
109 | + return false; |
|
110 | + } |
|
89 | 111 | |
90 | 112 | # ------------------------ |
91 | 113 | |
@@ -96,7 +118,9 @@ discard block |
||
96 | 118 | |
97 | 119 | public static function logout() { |
98 | 120 | |
99 | - if ((null === self::$user) || (0 === self::$user->id)) return false; |
|
121 | + if ((null === self::$user) || (0 === self::$user->id)) { |
|
122 | + return false; |
|
123 | + } |
|
100 | 124 | |
101 | 125 | # Remove session |
102 | 126 |
@@ -49,9 +49,13 @@ |
||
49 | 49 | |
50 | 50 | public static function url(string $value) { |
51 | 51 | |
52 | - if (false === ($value = parent::url($value))) return false; |
|
52 | + if (false === ($value = parent::url($value))) { |
|
53 | + return false; |
|
54 | + } |
|
53 | 55 | |
54 | - if (!preg_match('/^https?:\/\//', $value)) return false; |
|
56 | + if (!preg_match('/^https?:\/\//', $value)) { |
|
57 | + return false; |
|
58 | + } |
|
55 | 59 | |
56 | 60 | # ------------------------ |
57 | 61 |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | # Regular expressions |
4 | 4 | |
5 | -define('REGEX_MAP_ITEM_PATH', '/^[a-zA-Z0-9_\-\+\.\,\'\*\(\)\[\]:;!$%~]+$/'); |
|
6 | -define('REGEX_MAP_ITEM_HANDLER', '/^[A-Z][a-zA-Z0-9]*$/'); |
|
5 | +define('REGEX_MAP_ITEM_PATH', '/^[a-zA-Z0-9_\-\+\.\,\'\*\(\)\[\]:;!$%~]+$/'); |
|
6 | +define('REGEX_MAP_ITEM_HANDLER', '/^[A-Z][a-zA-Z0-9]*$/'); |
|
7 | 7 | |
8 | -define('REGEX_LANGUAGE_NAME', '/^[a-z][a-z]-[A-Z][A-Z]$/'); |
|
9 | -define('REGEX_TEMPLATE_NAME', '/^[A-Z0-9][a-zA-Z0-9]*$/'); |
|
8 | +define('REGEX_LANGUAGE_NAME', '/^[a-z][a-z]-[A-Z][A-Z]$/'); |
|
9 | +define('REGEX_TEMPLATE_NAME', '/^[A-Z0-9][a-zA-Z0-9]*$/'); |
|
10 | 10 | |
11 | -define('REGEX_USER_AUTH_CODE', '/^[a-zA-Z0-9]{40}$/'); |
|
11 | +define('REGEX_USER_AUTH_CODE', '/^[a-zA-Z0-9]{40}$/'); |
|
12 | 12 | |
13 | -define('REGEX_USER_NAME', '/^(?!_)(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
14 | -define('REGEX_USER_PASSWORD', '/^.+$/'); |
|
13 | +define('REGEX_USER_NAME', '/^(?!_)(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
14 | +define('REGEX_USER_PASSWORD', '/^.+$/'); |
|
15 | 15 | |
16 | -define('REGEX_FILE_NAME', '/^[^\/?%*:|"<>\\\]+$/'); |
|
16 | +define('REGEX_FILE_NAME', '/^[^\/?%*:|"<>\\\]+$/'); |