Conditions | 8 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public static function authorize(string $code, bool $admin) { |
||
29 | |||
30 | # Check code |
||
31 | |||
32 | if (false === ($code = Validate::authCode($code))) return false; |
||
33 | |||
34 | # Get auth |
||
35 | |||
36 | if (!($auth = Entitizer::get(static::$type))->init($code, 'code')) return false; |
||
37 | |||
38 | if (($auth->ip !== REQUEST_CLIENT_IP) || ($auth->time < (REQUEST_TIME - static::$lifetime))) return false; |
||
39 | |||
40 | # Get user |
||
41 | |||
42 | if (0 === ($user = Entitizer::get(TABLE_USERS, $auth->id))->id) return false; |
||
43 | |||
44 | if ($user->rank < ($admin ? RANK_ADMINISTRATOR : RANK_USER)) return false; |
||
45 | |||
46 | # ------------------------ |
||
47 | |||
48 | return ['auth' => $auth, 'user' => $user]; |
||
49 | } |
||
50 | } |
||
52 |