Total Complexity | 9 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class Auth extends Module |
||
13 | { |
||
14 | |||
15 | //TODO session_level isn't explicit enough. Have to change things up a bit. Probably use user_role_name and user_role_level |
||
16 | |||
17 | /** |
||
18 | * get the user type |
||
19 | * @return mixed |
||
20 | */ |
||
21 | public function getUser() |
||
22 | { |
||
23 | $session = $this->container->getSession(); |
||
24 | return $session->get('session_level'); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Gets the user level defined in the session (this is set on login and also stored in the DB). |
||
29 | * Returns an int for easier user control. |
||
30 | * @return int |
||
31 | */ |
||
32 | public function getUserLevel() |
||
33 | { |
||
34 | $session = $this->container->getSession(); |
||
35 | //For testing, setting the user level |
||
36 | //$session->set('session_level', 'Admin'); |
||
37 | |||
38 | //get session level from the actual $_SESSION |
||
39 | $sessionLevel = $session->get('session_level'); |
||
40 | //we could use a binary system for the rights but not much granular levels to take care of |
||
41 | if ($sessionLevel) { |
||
42 | if ($sessionLevel === 'Admin') { |
||
43 | return 2; |
||
44 | } |
||
45 | if ($sessionLevel === 'User') { |
||
46 | return 1; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return 0; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * is the connected user an Admin |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function isAdmin() |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * is the user connected ? |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function isUser() |
||
77 | } |
||
78 | } |