IndexController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\web\ForbiddenHttpException;
7
use app\modules\admin\models\forms\LoginForm;
8
9
/**
10
 * Allowed controller for all
11
 */
12
class IndexController extends \yii\web\Controller
13 14
{
14
    public function behaviors()
15
    {
16 14
        return [
17
            'access' => [
18
                'class' => 'yii\filters\AccessControl',
19
                'rules' => [
20
                    [
21
                        'allow'   => true,
22
                        'actions' => ['index'],
23
                        'roles'   => ['@', 'AdminModule'],
24
                    ],
25
                    [
26
                        'allow'   => true,
27
                        'actions' => ['login'],
28
                        'roles'   => ['?'],
29
                    ],
30
                    [
31
                        'allow'   => true,
32
                        'actions' => ['logout'],
33
                        'roles'   => ['@'],
34
                    ],
35
                    [
36
                        'allow'   => true,
37
                        'actions' => ['error'],
38
                        'roles'   => ['*'],
39
                    ],
40
                    // everything else is denied
41
                ],
42
            ],
43
            'verbs' => [
44
                'class' => 'yii\filters\VerbFilter',
45
                'actions' => [
46
                    'logout' => ['post'],
47
                ],
48
            ],
49
        ];
50
    }
51 3
52
    public function actionIndex()
53 3
    {
54 1
        if (!Yii::$app->user->can('AdminModule')) {
55
            throw new ForbiddenHttpException(Yii::t('app', 'Access Denied'));
56
        }
57 2
58
        return $this->render('index');
59
    }
60 14
61
    public function actionLogin()
62 14
    {
63
        $model = new LoginForm();
64 14
65 2
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
66
            return $this->goBack();
67 14
        }
68 14
        return $this->render('login', [
69
            'model' => $model,
70
        ]);
71
    }
72 1
73
    public function actionLogout()
74 1
    {
75 1
        Yii::$app->user->logout();
76
        return $this->goHome();
77
    }
78
}
79