Completed
Pull Request — master (#37)
by Elias
14:10
created

SecurityController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 49
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 20 1
A actionLogin() 0 14 2
1
<?php
2
/**
3
 * @link http://www.diemeisterei.de/
4
 * @copyright Copyright (c) 2020 diemeisterei GmbH, Stuttgart
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace app\controllers;
11
12
use Da\User\Form\LoginForm;
13
use Da\User\Traits\ContainerAwareTrait;
14
use dmstr\web\AdminLteAsset;
15
use yii\base\InvalidConfigException;
16
use yii\filters\AccessControl;
17
use yii\web\Controller;
18
use Yii;
19
20
/**
21
 * Security controller.
22
 */
23
class SecurityController extends Controller
24
{
25
    use ContainerAwareTrait;
26
27
    /**
28
     * @return array
29
     */
30
    public function behaviors()
31
    {
32
        $behaviors = parent::behaviors();
33
        $behaviors['access-control'] = [
34
            'class' => AccessControl::class,
35
            'rules' => [
36
                [
37
                    'allow' => true,
38
                    'actions' => [
39
                        'login'
40
                    ],
41
                    'roles' => [
42
                        '?',
43
                        '@'
44
                    ]
45
                ]
46
            ]
47
        ];
48
        return $behaviors;
49
    }
50
51
    /**
52
     * Renders the login page.
53
     *
54
     * @throws InvalidConfigException
55
     * @return string
56
     */
57
    public function actionLogin()
58
    {
59
        if (Yii::$app->user->isGuest === false) {
60
            return $this->goHome();
61
        }
62
63
        AdminLteAsset::register($this->view);
64
        $this->view->title = Yii::t('app', 'Sign in');
65
        $this->layout = '@app/views/layouts/plain';
66
67
        return $this->render('login', [
68
            'model' => $this->make(LoginForm::class)
69
        ]);
70
    }
71
}
72