Passed
Push — Showing-Posts ( 1f11b9...54555e )
by Stone
02:27
created

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