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

Auth::getUserLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
}