Completed
Push — master ( 53489f...89bc16 )
by Igor
02:21
created

SiteController::actionAccount()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 3
eloc 9
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 app\models\UserModel;
8
use yii\web\Controller;
9
use yii\filters\VerbFilter;
10
use Yii;
11
use yii2mod\rbac\components\AccessControl;
12
13
/**
14
 * Class SiteController
15
 * @package app\controllers
16
 */
17
class SiteController extends Controller
18
{
19
    /**
20
     * Returns a list of behaviors that this component should behave as.
21
     *
22
     * Child classes may override this method to specify the behaviors they want to behave as.
23
     * @return array
24
     */
25
    public function behaviors()
26
    {
27
        return [
28
            'access' => [
29
                'class' => AccessControl::className(),
30
            ],
31
            'verbs' => [
32
                'class' => VerbFilter::className(),
33
                'actions' => [
34
                    'logout' => ['post'],
35
                ],
36
            ],
37
        ];
38
    }
39
40
    /**
41
     * Declares external actions for the controller.
42
     * @return array
43
     */
44
    public function actions()
45
    {
46
        return [
47
            'error' => [
48
                'class' => 'yii\web\ErrorAction',
49
            ],
50
            'captcha' => [
51
                'class' => 'yii\captcha\CaptchaAction',
52
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
53
            ],
54
            'login' => [
55
                'class' => 'yii2mod\user\actions\LoginAction'
56
            ],
57
            'logout' => [
58
                'class' => 'yii2mod\user\actions\LogoutAction'
59
            ],
60
            'signup' => [
61
                'class' => 'yii2mod\user\actions\SignupAction'
62
            ],
63
            'request-password-reset' => [
64
                'class' => 'yii2mod\user\actions\RequestPasswordResetAction'
65
            ],
66
            'password-reset' => [
67
                'class' => 'yii2mod\user\actions\PasswordResetAction'
68
            ],
69
            'page' => [
70
                'class' => 'yii2mod\cms\actions\PageAction',
71
            ],
72
        ];
73
    }
74
75
    /**
76
     * Index action
77
     * @return string
78
     */
79
    public function actionIndex()
80
    {
81
        return $this->render('index');
82
    }
83
84
    /**
85
     * Contact us action
86
     * @return string|\yii\web\Response
87
     */
88
    public function actionContact()
89
    {
90
        $model = new ContactForm();
91
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
92
            if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
93
                Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
94
            } else {
95
                Yii::$app->session->setFlash('error', 'There was an error sending email.');
96
            }
97
            return $this->refresh();
98
        } else {
99
            return $this->render('contact', [
100
                'model' => $model,
101
            ]);
102
        }
103
    }
104
105
    /**
106
     * Account action
107
     */
108
    public function actionAccount()
109
    {
110
        /* @var $userModel UserModel */
111
        $userModel = Yii::$app->user->identity;
112
        $resetPasswordForm = new ResetPasswordForm($userModel);
113
        if ($resetPasswordForm->load(Yii::$app->request->post()) && $resetPasswordForm->resetPassword()) {
114
            Yii::$app->session->setFlash('success', Yii::t('app', 'Password has been updated.'));
115
            return $this->refresh();
116
        }
117
        return $this->render('account', [
118
            'resetPasswordForm' => $resetPasswordForm,
119
            'userModel' => $userModel
120
        ]);
121
    }
122
123
}
124