MyController::actionChangePassword()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 0
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace zacksleo\yii2\backend\controllers;
4
5
use zacksleo\yii2\backend\models\forms\ChangePasswordForm;
6
use yii;
7
use zacksleo\yii2\backend\models\Admin;
8
use yii\web\Controller;
9
use yii\filters\AccessControl;
10
11
class MyController extends Controller
12
{
13
    public $layout = '@vendor/zacksleo/yii2-backend/src/views/my/layouts';
14
15 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...
16
    {
17
        return [
18
            'access' => [
19
                '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...
20
                'rules' => [
21
                    [
22
                        'allow' => true,
23
                        'actions' => ['profile', 'change-password', 'avatar'],
24
                        'roles' => ['@'],
25
                    ]
26
                ],
27
            ]
28
        ];
29
    }
30
31
    /**
32
     * 设置头像
33
     * @return string|yii\web\Response
34
     */
35 View Code Duplication
    public function actionAvatar()
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...
36
    {
37
        $model = Admin::findOne(Yii::$app->user->id);
38
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
39
            Yii::$app->session->setFlash('success', '修改成功');
40
            return $this->redirect(['avatar']);
41
        } else {
42
            return $this->render('avatar', [
43
                'model' => $model
44
            ]);
45
        }
46
    }
47
48
    /**
49
     * 修改密码
50
     * @return string|yii\web\Response
51
     */
52 View Code Duplication
    public function actionChangePassword()
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...
53
    {
54
        $model = new ChangePasswordForm();
55
        if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
56
            Yii::$app->session->setFlash('success', '修改成功');
57
            return $this->redirect(['change-password']);
58
        } else {
59
            return $this->render('change-password', [
60
                'model' => $model
61
            ]);
62
        }
63
    }
64
65
    /**
66
     * 设置个人信息
67
     * @return string|yii\web\Response
68
     */
69 View Code Duplication
    public function actionProfile()
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...
70
    {
71
        $model = Admin::findOne(Yii::$app->user->id);
72
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
73
            Yii::$app->session->setFlash('success', '修改成功');
74
            return $this->redirect(['profile']);
75
        } else {
76
            return $this->render('profile', [
77
                'model' => $model
78
            ]);
79
        }
80
    }
81
}
82