SiteController::actionAccount()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 5
Ratio 35.71 %

Importance

Changes 0
Metric Value
dl 5
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
3
namespace app\controllers;
4
5
use app\models\forms\ContactForm;
6
use app\models\forms\ResetPasswordForm;
7
use Yii;
8
use yii\filters\VerbFilter;
9
use yii\web\Controller;
10
use yii2mod\rbac\filters\AccessControl;
11
12
/**
13
 * Class SiteController
14
 *
15
 * @package app\controllers
16
 */
17
class SiteController extends Controller
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function behaviors(): array
23
    {
24
        return [
25
            'access' => [
26
                'class' => AccessControl::class,
27
                'only' => [
28
                    'login',
29
                    'logout',
30
                    'signup',
31
                    'request-password-reset',
32
                    'password-reset',
33
                    'account',
34
                ],
35
                'rules' => [
36
                    [
37
                        'allow' => true,
38
                        'actions' => ['login', 'signup', 'request-password-reset', 'password-reset'],
39
                        'roles' => ['?'],
40
                    ],
41
                    [
42
                        'allow' => true,
43
                        'actions' => ['logout', 'account'],
44
                        'roles' => ['@'],
45
                    ],
46
                ],
47
            ],
48
            'verbs' => [
49
                'class' => VerbFilter::class,
50
                'actions' => [
51
                    'index' => ['get'],
52
                    'contact' => ['get', 'post'],
53
                    'account' => ['get', 'post'],
54
                    'login' => ['get', 'post'],
55
                    'logout' => ['post'],
56
                    'signup' => ['get', 'post'],
57
                    'request-password-reset' => ['get', 'post'],
58
                    'password-reset' => ['get', 'post'],
59
                    'page' => ['get', 'post'],
60
                ],
61
            ],
62
        ];
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function actions(): array
69
    {
70
        return [
71
            'error' => [
72
                'class' => 'yii\web\ErrorAction',
73
            ],
74
            'captcha' => [
75
                'class' => 'yii\captcha\CaptchaAction',
76
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
77
            ],
78
            'login' => [
79
                'class' => 'yii2mod\user\actions\LoginAction',
80
            ],
81
            'logout' => [
82
                'class' => 'yii2mod\user\actions\LogoutAction',
83
            ],
84
            'signup' => [
85
                'class' => 'yii2mod\user\actions\SignupAction',
86
            ],
87
            'request-password-reset' => [
88
                'class' => 'yii2mod\user\actions\RequestPasswordResetAction',
89
            ],
90
            'password-reset' => [
91
                'class' => 'yii2mod\user\actions\PasswordResetAction',
92
            ],
93
            'page' => [
94
                'class' => 'yii2mod\cms\actions\PageAction',
95
            ],
96
        ];
97
    }
98
99
    /**
100
     * Displays homepage.
101
     *
102
     * @return string
103
     */
104
    public function actionIndex()
105
    {
106
        return $this->render('index');
107
    }
108
109
    /**
110
     * Displays contact page.
111
     *
112
     * @return string|\yii\web\Response
113
     */
114
    public function actionContact()
115
    {
116
        $model = new ContactForm();
117
118
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
119
            if ($model->contact(Yii::$app->params['adminEmail'])) {
120
                Yii::$app->session->setFlash('success', Yii::t('app', 'Thank you for contacting us. We will respond to you as soon as possible.'));
121
            } else {
122
                Yii::$app->session->setFlash('error', Yii::t('app', 'There was an error sending email.'));
123
            }
124
125
            return $this->refresh();
126
        }
127
128
        return $this->render('contact', [
129
            'model' => $model,
130
        ]);
131
    }
132
133
    /**
134
     * Displays account page.
135
     *
136
     * @return string|\yii\web\Response
137
     */
138
    public function actionAccount()
139
    {
140
        $resetPasswordForm = new ResetPasswordForm(Yii::$app->user->identity);
141
142 View Code Duplication
        if ($resetPasswordForm->load(Yii::$app->request->post()) && $resetPasswordForm->resetPassword()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
143
            Yii::$app->session->setFlash('success', Yii::t('app', 'Password has been updated.'));
144
145
            return $this->refresh();
146
        }
147
148
        return $this->render('account', [
149
            'resetPasswordForm' => $resetPasswordForm,
150
        ]);
151
    }
152
}
153