Completed
Push — dev ( 1806ac )
by Stone
12s
created

Auth   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAdmin() 0 7 2
A getUserLevel() 0 4 1
A getUser() 0 4 1
A isUser() 0 7 2
1
<?php
2
3
namespace Core\Modules;
4
5
use \Core\Container;
6
7
/**
8
 * Authentication class taking care of access rights
9
 * Class Auth
10
 * @package Core\Modules
11
 */
12
class Auth extends Module
13
{
14
15
    /**
16
     * get the user type
17
     * @return mixed
18
     */
19
    public function getUser()
20
    {
21
        $session = $this->container->getSession();
22
        return $session->get('user_role_name');
23
    }
24
25
    /**
26
     * Gets the user level defined in the session (this is set on login and also stored in the DB).
27
     * Returns an int for easier user control.
28
     * @return int
29
     */
30
    public function getUserLevel(): int
31
    {
32
        $session = $this->container->getSession();
33
        return $session->get('user_role_level') ?? 0;
34
    }
35
36
    /**
37
     * is the connected user an Admin
38
     * @return bool
39
     */
40
    public function isAdmin()
41
    {
42
        $userLevel = $this->getUserLevel();
43
        if ($userLevel > 1) {
44
            return true;
45
        }
46
        return false;
47
    }
48
49
    /**
50
     * is the user connected ?
51
     * @return bool
52
     */
53
    public function isUser()
54
    {
55
        $userLevel = $this->getUserLevel();
56
        if ($userLevel > 0) {
57
            return true;
58
        }
59
        return false;
60
    }
61
}