1 | <?php |
||||||
2 | namespace App\Http\Controller; |
||||||
3 | |||||||
4 | use App\Http\Form\ContactForm; |
||||||
5 | use App\Http\Form\LoginForm; |
||||||
6 | use App\Http\Form\PasswordResetRequestForm; |
||||||
7 | use App\Http\Form\ResendVerificationEmailForm; |
||||||
8 | use App\Http\Form\ResetPasswordForm; |
||||||
9 | use App\Http\Form\SignupForm; |
||||||
10 | use App\Http\Form\VerifyEmailForm; |
||||||
11 | use Yii; |
||||||
12 | use yii\base\InvalidArgumentException; |
||||||
13 | use yii\captcha\CaptchaAction; |
||||||
14 | use yii\web\BadRequestHttpException; |
||||||
15 | use yii\web\ErrorAction; |
||||||
16 | |||||||
17 | class SiteController extends Controller |
||||||
18 | { |
||||||
19 | /** |
||||||
20 | * {@inheritdoc} |
||||||
21 | */ |
||||||
22 | public function actions() |
||||||
23 | { |
||||||
24 | return [ |
||||||
25 | 'error' => [ |
||||||
26 | 'class' => ErrorAction::class, |
||||||
27 | ], |
||||||
28 | 'captcha' => [ |
||||||
29 | 'class' => CaptchaAction::class, |
||||||
30 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, |
||||||
31 | ], |
||||||
32 | ]; |
||||||
33 | } |
||||||
34 | |||||||
35 | /** |
||||||
36 | * Displays homepage. |
||||||
37 | * |
||||||
38 | * @return mixed |
||||||
39 | */ |
||||||
40 | public function actionIndex() |
||||||
41 | { |
||||||
42 | return $this->render('index'); |
||||||
43 | } |
||||||
44 | |||||||
45 | /** |
||||||
46 | * Displays contact page. |
||||||
47 | * |
||||||
48 | * @return mixed |
||||||
49 | */ |
||||||
50 | public function actionContact() |
||||||
51 | { |
||||||
52 | $model = new ContactForm(); |
||||||
53 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||||||
54 | if ($model->sendEmail(Yii::$app->params['adminEmail'])) { |
||||||
55 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will get in touch with you as soon as possible.'); |
||||||
0 ignored issues
–
show
|
|||||||
56 | } else { |
||||||
57 | Yii::$app->session->setFlash('error', 'There was an error sending your message.'); |
||||||
58 | } |
||||||
59 | |||||||
60 | return $this->refresh(); |
||||||
61 | } |
||||||
62 | |||||||
63 | return $this->render('contact', [ |
||||||
64 | 'model' => $model, |
||||||
65 | ]); |
||||||
66 | } |
||||||
67 | |||||||
68 | /** |
||||||
69 | * Displays about page. |
||||||
70 | * |
||||||
71 | * @return mixed |
||||||
72 | */ |
||||||
73 | public function actionAbout() |
||||||
74 | { |
||||||
75 | return $this->render('about'); |
||||||
76 | } |
||||||
77 | |||||||
78 | /** |
||||||
79 | * Logs out the current user. |
||||||
80 | * |
||||||
81 | * @return mixed |
||||||
82 | */ |
||||||
83 | public function actionLogin() |
||||||
84 | { |
||||||
85 | if (!Yii::$app->user->isGuest) { |
||||||
86 | return $this->goHome(); |
||||||
87 | } |
||||||
88 | |||||||
89 | $model = new LoginForm(); |
||||||
90 | if ($model->load(Yii::$app->request->post()) && $model->login()) { |
||||||
91 | return $this->goBack(); |
||||||
92 | } |
||||||
93 | |||||||
94 | $model->password = ''; |
||||||
95 | return $this->render('login', [ |
||||||
96 | 'model' => $model, |
||||||
97 | ]); |
||||||
98 | } |
||||||
99 | |||||||
100 | /** |
||||||
101 | * Logs out the current user. |
||||||
102 | * |
||||||
103 | * @return mixed |
||||||
104 | */ |
||||||
105 | public function actionLogout() |
||||||
106 | { |
||||||
107 | Yii::$app->user->logout(); |
||||||
0 ignored issues
–
show
The method
logout() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
108 | |||||||
109 | return $this->goHome(); |
||||||
110 | } |
||||||
111 | |||||||
112 | /** |
||||||
113 | * Signs user up. |
||||||
114 | * |
||||||
115 | * @return mixed |
||||||
116 | */ |
||||||
117 | public function actionSignup() |
||||||
118 | { |
||||||
119 | $model = new SignupForm(); |
||||||
120 | if ($model->load(Yii::$app->request->post()) && $model->signup()) { |
||||||
121 | Yii::$app->session->setFlash('success', 'Thank you for registration. Please check your inbox for verification email.'); |
||||||
122 | return $this->goHome(); |
||||||
123 | } |
||||||
124 | |||||||
125 | return $this->render('signup', [ |
||||||
126 | 'model' => $model, |
||||||
127 | ]); |
||||||
128 | } |
||||||
129 | |||||||
130 | /** |
||||||
131 | * Requests password reset. |
||||||
132 | * |
||||||
133 | * @return mixed |
||||||
134 | */ |
||||||
135 | public function actionRequestPasswordReset() |
||||||
136 | { |
||||||
137 | $model = new PasswordResetRequestForm(); |
||||||
138 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||||||
139 | if ($model->sendEmail()) { |
||||||
140 | Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); |
||||||
141 | |||||||
142 | return $this->goHome(); |
||||||
143 | } else { |
||||||
144 | Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for the provided email address.'); |
||||||
145 | } |
||||||
146 | } |
||||||
147 | |||||||
148 | return $this->render('requestPasswordResetToken', [ |
||||||
149 | 'model' => $model, |
||||||
150 | ]); |
||||||
151 | } |
||||||
152 | |||||||
153 | /** |
||||||
154 | * Resets password. |
||||||
155 | * |
||||||
156 | * @param string $token |
||||||
157 | * @return mixed |
||||||
158 | * @throws BadRequestHttpException |
||||||
159 | */ |
||||||
160 | public function actionResetPassword($token) |
||||||
161 | { |
||||||
162 | try { |
||||||
163 | $model = new ResetPasswordForm($token); |
||||||
164 | } catch (InvalidArgumentException $e) { |
||||||
165 | throw new BadRequestHttpException($e->getMessage()); |
||||||
166 | } |
||||||
167 | |||||||
168 | if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { |
||||||
169 | Yii::$app->session->setFlash('success', 'New password saved.'); |
||||||
170 | |||||||
171 | return $this->goHome(); |
||||||
172 | } |
||||||
173 | |||||||
174 | return $this->render('resetPassword', [ |
||||||
175 | 'model' => $model, |
||||||
176 | ]); |
||||||
177 | } |
||||||
178 | |||||||
179 | /** |
||||||
180 | * Verify email address |
||||||
181 | * |
||||||
182 | * @param string $token |
||||||
183 | * @throws BadRequestHttpException |
||||||
184 | * @return yii\web\Response |
||||||
185 | */ |
||||||
186 | public function actionVerifyEmail($token) |
||||||
187 | { |
||||||
188 | try { |
||||||
189 | $model = new VerifyEmailForm($token); |
||||||
190 | } catch (InvalidArgumentException $e) { |
||||||
191 | throw new BadRequestHttpException($e->getMessage()); |
||||||
192 | } |
||||||
193 | if ($user = $model->verifyEmail()) { |
||||||
194 | if (Yii::$app->user->login($user)) { |
||||||
195 | Yii::$app->session->setFlash('success', 'Your email has been confirmed!'); |
||||||
196 | return $this->goHome(); |
||||||
197 | } |
||||||
198 | } |
||||||
199 | |||||||
200 | Yii::$app->session->setFlash('error', 'Sorry, we are unable to verify your account with provided token.'); |
||||||
201 | return $this->goHome(); |
||||||
202 | } |
||||||
203 | |||||||
204 | /** |
||||||
205 | * Resend verification email |
||||||
206 | * |
||||||
207 | * @return mixed |
||||||
208 | */ |
||||||
209 | public function actionResendVerificationEmail() |
||||||
210 | { |
||||||
211 | $model = new ResendVerificationEmailForm(); |
||||||
212 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||||||
213 | if ($model->sendEmail()) { |
||||||
214 | Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); |
||||||
215 | return $this->goHome(); |
||||||
216 | } |
||||||
217 | Yii::$app->session->setFlash('error', 'Sorry, we are unable to resend verification email for the provided email address.'); |
||||||
218 | } |
||||||
219 | |||||||
220 | return $this->render('resendVerificationEmail', [ |
||||||
221 | 'model' => $model |
||||||
222 | ]); |
||||||
223 | } |
||||||
224 | } |
||||||
225 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.