AdminController::onlyAdmin()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Core;
4
5
/**
6
 * The parent controller for all admin section controllers
7
 * Class AdminController
8
 * @package Core
9
 */
10
abstract class AdminController extends Controller
11
{
12
    /**
13
     * Out placeholders for modules
14
     * @var object
15
     */
16
    protected $alertBox;
17
18
    public function __construct(Container $container)
19
    {
20
21
        $this->loadModules[] = 'AlertBox';
22
        parent::__construct($container);
23
24
        //Sending the auth level to the data
25
        $this->data['userRole'] = $this->auth->getUserRole();
26
        $this->data['userLevel'] = $this->auth->getUserLevel();
27
28
    }
29
30
    /**
31
     * Only allow admin
32
     */
33
    protected function onlyAdmin()
34
    {
35
        if (!$this->auth->isAdmin()) {
36
            $this->alertBox->setAlert("Only admins can access this", 'error');
37
            $this->container->getResponse()->redirect('/admin');
38
        }
39
    }
40
41
    /**
42
     * Only allow post messages
43
     */
44
    protected function onlyPost()
45
    {
46
        //is post
47
        if (!$this->request->isPost()) {
48
            $this->alertBox->setAlert('Only post messages allowed', 'error');
49
            $this->response->redirect('/admin');
50
        }
51
    }
52
53
54
}