Completed
Push — master ( 5e7707...6e3d76 )
by Igor
03:56
created

IndexController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 67
ccs 0
cts 57
cp 0
rs 10
c 0
b 0
f 0

4 Methods

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