Passed
Push — Auth ( 9ea218...52ac6b )
by Stone
02:22
created

AdminController::onlyPost()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
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
    protected function onlyAdmin()
31
    {
32
        if (!$this->auth->isAdmin()) {
33
            $this->alertBox->setAlert("Only admins can access this", 'error');
34
            $this->container->getResponse()->redirect('/admin');
35
        }
36
    }
37
38
    /**
39
     * Only allow post messages
40
     */
41
    protected function onlyPost()
42
    {
43
        //is post
44
        if (!$this->request->isPost()) {
45
            $this->alertBox->setAlert('Only post messages allowed', 'error');
46
            $this->response->redirect('/admin');
47
        }
48
    }
49
50
51
}