Completed
Push — master ( c4e316...a2ecb8 )
by vistart
02:57
created

SecurityController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 15 1
A actionIndex() 0 4 1
A actionChangePassword() 0 13 3
A actionLoginLog() 0 4 1
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\ChangePasswordForm;
16
use Yii;
17
use yii\filters\AccessControl;
18
use yii\web\Controller;
19
20
/**
21
 * @version 1.0
22
 * @author vistart <[email protected]>
23
 */
24
class SecurityController extends Controller
25
{
26
    const SESSION_KEY_CHANGE_PASSWORD_MESSAGE = 'session_key_change_password_message';
27
28
    public $changePasswordSuccessMessage = 'Password Changed.';
29
30
    public $changePasswordFailedMessage = 'Password Not Changed.';
31
32
    public function behaviors()
33
    {
34
        return [
35
            'access' => [
36
                'class' => AccessControl::class,
37
                'rules' => [
38
                    [
39
                        'actions' => ['index', 'change-password', 'login-log'],
40
                        'allow' => allow,
41
                        'roles' => ['@'],
42
                    ]
43
                ],
44
            ],
45
        ];
46
    }
47
48
    public function actionIndex()
49
    {
50
        return $this->render('index');
51
    }
52
53
    public function actionChangePassword()
54
    {
55
        $model = new ChangePasswordForm();
56
        if ($model->load(Yii::$app->request->post()) && $model->changePassword()) {
57
            $model = new ChangePasswordForm();
58
            Yii::$app->session->setFlash(self::SESSION_KEY_CHANGE_PASSWORD_MESSAGE, $this->changePasswordSuccessMessage);
59
        } else {
60
            $model = new ChangePasswordForm();
61
            Yii::$app->session->setFlash(self::SESSION_KEY_CHANGE_PASSWORD_MESSAGE, $this->changePasswordFailedMessage);
62
            
63
        }
64
        return $this->render('change-password', ['model' => $model]);
65
    }
66
67
    public function actionLoginLog()
68
    {
69
        return $this->render('login-log');
70
    }
71
}
72