SiteController::actionRequestpasswordreset()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace zacksleo\yii2\backend\tests\controllers;
4
5
use yii;
6
use yii\base\InvalidParamException;
7
use yii\web\BadRequestHttpException;
8
use yii\web\Controller;
9
use yii\filters\AccessControl;
10
use zacksleo\yii2\backend\models\forms\LoginForm;
11
use zacksleo\yii2\backend\models\forms\PasswordResetRequestForm;
12
use zacksleo\yii2\backend\models\forms\ResetPasswordForm;
13
14
/**
15
 * Default controller for the `backend` module
16
 */
17
class SiteController extends Controller
18
{
19
    public $layout = '@vendor/zacksleo/yii2-backend/src/views/layouts/layout';
20
    public $_viewPath = '@vendor/zacksleo/yii2-backend/src/views/site/';
21
22 View Code Duplication
    public function behaviors()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        return [
25
            'access' => [
26
                'class' => AccessControl::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
27
                'only' => ['login', 'logout', 'index'],
28
                'rules' => [
29
                    [
30
                        'allow' => true,
31
                        'actions' => ['login'],
32
                        'roles' => ['?'],
33
                    ],
34
                    [
35
                        'allow' => true,
36
                        'actions' => ['index', 'logout'],
37
                        'roles' => ['@'],
38
                    ]
39
                ],
40
            ]
41
        ];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function actions()
48
    {
49
        return [
50
            'error' => [
51
                'class' => 'yii\web\ErrorAction',
52
                'view' => '@vendor/zacksleo/yii2-backend/src/views/site/error'
53
            ],
54
        ];
55
    }
56
57
    public function actionLogin()
58
    {
59
        $model = new LoginForm();
60
        return $model->load(Yii::$app->request->post()) && $model->login();
61
    }
62
63
    /**
64
     * User logout
65
     */
66
    public function actionLogout()
67
    {
68
        return Yii::$app->user->logout();
69
    }
70
71
    /**
72
     * Requests password reset.
73
     *
74
     * @return mixed
75
     */
76
    public function actionRequestpasswordreset()
77
    {
78
        $model = new PasswordResetRequestForm();
79
        return $model->load(Yii::$app->request->bodyParams) && $model->validate() && $model->sendEmail();
80
    }
81
82
    /**
83
     * Resets password.
84
     *
85
     * @param string $token
86
     * @return mixed
87
     * @throws BadRequestHttpException
88
     */
89
    public function actionResetpassword($token)
90
    {
91
        try {
92
            $model = new ResetPasswordForm($token);
93
        } catch (InvalidParamException $e) {
94
            throw new BadRequestHttpException($e->getMessage());
95
        }
96
        $model->load(Yii::$app->request->bodyParams);
97
        return $model->load(Yii::$app->request->bodyParams) && $model->validate() && $model->resetPassword();
98
    }
99
}
100