AuthController::actionLogout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\web\user\controllers;
14
15
use rhosocial\user\forms\LoginForm;
16
use Yii;
17
use yii\filters\AccessControl;
18
use yii\filters\VerbFilter;
19
use yii\web\Controller;
20
21
/**
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class AuthController extends Controller
26
{
27
    /**
28
     * @inheritdoc
29
     */
30
    public function behaviors()
31
    {
32
        return [
33
            'access' => [
34
                'class' => AccessControl::class,
35
                'only' => ['logout'],
36
                'rules' => [
37
                    [
38
                        'actions' => ['logout'],
39
                        'allow' => true,
40
                        'roles' => ['@'],
41
                    ],
42
                ],
43
            ],
44
            'verbs' => [
45
                'class' => VerbFilter::class,
46
                'actions' => [
47
                    'logout' => ['post'],
48
                ],
49
            ],
50
        ];
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function actions()
57
    {
58
        return [
59
            'error' => [
60
                'class' => 'yii\web\ErrorAction',
61
            ],
62
            'captcha' => [
63
                'class' => 'yii\captcha\CaptchaAction',
64
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
65
            ],
66
        ];
67
    }
68
69
    /**
70
     * Login action.
71
     *
72
     * @return string
73
     */
74
    public function actionLogin($id = '')
75
    {
76
        if (!Yii::$app->user->isGuest) {
77
            return $this->goHome();
78
        }
79
80
        $model = new LoginForm();
81
        if (!empty($id) && is_numeric($id)) {
82
            $model->id = $id;
83
        }
84
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
85
            return $this->goBack();
86
        }
87
        return $this->render('login', [
88
            'model' => $model,
89
        ]);
90
    }
91
92
    /**
93
     * Logout action.
94
     *
95
     * @return string
96
     */
97
    public function actionLogout()
98
    {
99
        Yii::$app->user->logout();
100
101
        return $this->goHome();
102
    }
103
}
104