1 | <?php |
||
19 | class IndexController extends BaseController |
||
20 | { |
||
21 | /** |
||
22 | * @inheritdoc |
||
23 | */ |
||
24 | 57 | public function behaviors() |
|
25 | { |
||
26 | return [ |
||
27 | 'access' => [ |
||
28 | 57 | 'class' => AccessControl::className(), |
|
29 | 57 | 'only' => ['logout', 'signup', 'signup-provider', 'auth', 'confirm-request'], |
|
30 | 'rules' => [ |
||
31 | [ |
||
32 | 57 | 'actions' => ['signup', 'signup-provider', 'auth'], |
|
33 | 57 | 'allow' => true, |
|
34 | 57 | 'roles' => ['?'], |
|
35 | 57 | ], |
|
36 | [ |
||
37 | 57 | 'actions' => ['logout', 'confirm-request'], |
|
38 | 57 | 'allow' => true, |
|
39 | 57 | 'roles' => ['@'], |
|
40 | 57 | ], |
|
41 | 57 | ], |
|
42 | 57 | ], |
|
43 | 'verbs' => [ |
||
44 | 57 | 'class' => VerbFilter::className(), |
|
45 | 'actions' => [ |
||
46 | 57 | 'logout' => ['post'], |
|
47 | 57 | ], |
|
48 | 57 | ], |
|
49 | 57 | ]; |
|
50 | 2 | } |
|
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | 57 | public function actions() |
|
68 | |||
69 | 8 | public function successCallback($client) |
|
77 | |||
78 | 24 | public function actionIndex() |
|
82 | |||
83 | 16 | public function actionLogin() |
|
84 | { |
||
85 | 16 | if (!Yii::$app->user->isGuest) { |
|
86 | 1 | return $this->goHome(); |
|
87 | } |
||
88 | |||
89 | 16 | $model = new LoginForm(); |
|
90 | 16 | if ($model->load(Yii::$app->request->post()) && $model->login()) { |
|
91 | 6 | return $this->goBack(); |
|
92 | 3 | } |
|
93 | 16 | return $this->render('login', [ |
|
94 | 16 | 'model' => $model, |
|
95 | 16 | ]); |
|
96 | 3 | } |
|
97 | |||
98 | 15 | public function actionSignup() |
|
99 | { |
||
100 | 15 | $model = new SignupForm(); |
|
101 | 15 | if ($model->load(Yii::$app->request->post()) && $model->signup()) { |
|
102 | 3 | if ($model->sendEmail()) { |
|
103 | 1 | Yii::$app->session->setFlash( |
|
104 | 1 | 'success', |
|
105 | 1 | Yii::t( |
|
106 | 1 | 'app.messages', |
|
107 | 'Please activate your account' |
||
108 | 1 | ) . '. ' . |
|
109 | 1 | Yii::t( |
|
110 | 1 | 'app.messages', |
|
111 | 1 | 'A letter for activation was sent to {email}', |
|
112 | 1 | ['email' => $model->email] |
|
113 | 1 | ) |
|
114 | 1 | ); |
|
115 | 1 | return $this->goHome(); |
|
116 | } |
||
117 | 2 | Yii::$app->session->setFlash( |
|
118 | 2 | 'error', |
|
119 | 2 | Yii::t( |
|
120 | 2 | 'app.messages', |
|
121 | 'An error occurred while sending a message to activate account' |
||
122 | 2 | ) |
|
123 | 2 | ); |
|
124 | 2 | return $this->goHome(); |
|
125 | } |
||
126 | |||
127 | 15 | return $this->render('signup', [ |
|
128 | 15 | 'model' => $model, |
|
129 | 15 | ]); |
|
130 | } |
||
131 | |||
132 | 8 | public function actionSignupProvider() |
|
133 | { |
||
134 | 8 | $session = Yii::$app->session; |
|
135 | 8 | $provider = $session['provider']; |
|
136 | 8 | if ($provider === null) { |
|
137 | return $this->goHome(); |
||
138 | } |
||
139 | |||
140 | 8 | $model = new SignupProviderForm($provider); |
|
141 | |||
142 | // check exist user and provider |
||
143 | 8 | if ($user = User::findByProvider($provider['type'], $provider['profile']['id'])) { |
|
144 | 2 | $session['provider'] = null; |
|
145 | 2 | if ($user->isActive()) { |
|
146 | 1 | $user->updateProvider($model->parseProvider()); |
|
|
|||
147 | 1 | $user->authorize(true); |
|
148 | 1 | return $this->goHome(); |
|
149 | } |
||
150 | 1 | $session->setFlash('error', $user->getStatusDescription()); |
|
151 | 1 | return $this->goHome(); |
|
152 | } |
||
153 | |||
154 | 8 | $model->prepareUser(); |
|
155 | |||
156 | 8 | if ($model->isVerifiedEmail() && $model->signup(false)) { |
|
157 | 1 | $session['provider'] = null; |
|
158 | 1 | return $this->goHome(); |
|
159 | } |
||
160 | |||
161 | 7 | if ($model->load(Yii::$app->request->post()) && $model->signup()) { |
|
162 | 5 | $session['provider'] = null; |
|
163 | 5 | if ($model->sendEmail()) { |
|
164 | 4 | $session->setFlash( |
|
165 | 4 | 'success', |
|
166 | 4 | Yii::t( |
|
167 | 4 | 'app.messages', |
|
168 | 'Please activate your account' |
||
169 | 4 | ) . '. ' . |
|
170 | 4 | Yii::t( |
|
171 | 4 | 'app.messages', |
|
172 | 4 | 'A letter for activation was sent to {email}', |
|
173 | 4 | ['email' => $model->email] |
|
174 | 4 | ) |
|
175 | 4 | ); |
|
176 | 4 | return $this->goHome(); |
|
177 | } |
||
178 | 1 | $session->setFlash( |
|
179 | 1 | 'error', |
|
180 | 1 | Yii::t( |
|
181 | 1 | 'app.messages', |
|
182 | 'An error occurred while sending a message to activate account' |
||
183 | 1 | ) |
|
184 | 1 | ); |
|
185 | 1 | return $this->goHome(); |
|
186 | } |
||
187 | |||
188 | 7 | return $this->render('signupProvider', [ |
|
189 | 'model' => $model |
||
190 | 7 | ]); |
|
191 | } |
||
192 | |||
193 | 3 | public function actionConfirmRequest() |
|
194 | { |
||
195 | 3 | $user = Yii::$app->user->identity; |
|
196 | 3 | if ($user->isConfirmed()) { |
|
197 | 1 | Http::exception(403); |
|
198 | } // @codeCoverageIgnore |
||
199 | |||
200 | 2 | $model = new ConfirmEmailForm(); |
|
201 | |||
202 | 2 | if ($model->sendEmail($user)) { |
|
203 | 1 | Yii::$app->session->setFlash( |
|
204 | 1 | 'success', |
|
205 | 1 | Yii::t( |
|
206 | 1 | 'app.messages', |
|
207 | 1 | 'A letter for activation was sent to {email}', |
|
208 | 1 | ['email' => $user->email] |
|
209 | 1 | ) |
|
210 | 1 | ); |
|
211 | 1 | return $this->goHome(); |
|
212 | } |
||
213 | 1 | Yii::$app->session->setFlash( |
|
214 | 1 | 'error', |
|
215 | 1 | Yii::t( |
|
216 | 1 | 'app.messages', |
|
217 | 'An error occurred while sending a message to activate account' |
||
218 | 1 | ) |
|
219 | 1 | ); |
|
220 | 1 | return $this->goHome(); |
|
221 | } |
||
222 | |||
223 | 3 | public function actionConfirmEmail($token) |
|
224 | { |
||
225 | 3 | $model = new ConfirmEmailForm(); |
|
226 | |||
227 | 3 | if (!$model->validateToken($token)) { |
|
228 | 2 | Yii::$app->session->setFlash( |
|
229 | 2 | 'error', |
|
230 | 2 | Yii::t('app.messages', 'Invalid link for activate account') |
|
231 | 2 | ); |
|
232 | 2 | return $this->goHome(); |
|
233 | } |
||
234 | |||
235 | 1 | if ($model->confirmEmail()) { |
|
236 | 1 | Yii::$app->session->setFlash( |
|
237 | 1 | 'success', |
|
238 | 1 | Yii::t('app.messages', 'Your account is successfully activated') |
|
239 | 1 | ); |
|
240 | 1 | } |
|
241 | 1 | return $this->goHome(); |
|
242 | } |
||
243 | |||
244 | 8 | public function actionRequestPasswordReset() |
|
245 | { |
||
246 | 8 | $model = new PasswordResetRequestForm(); |
|
247 | |||
248 | 8 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
249 | 2 | if ($model->sendEmail()) { |
|
250 | 1 | Yii::$app->session->setFlash( |
|
251 | 1 | 'success', |
|
252 | 1 | Yii::t( |
|
253 | 1 | 'app.messages', |
|
254 | 'We\'ve sent you an email with instructions to reset your password' |
||
255 | 1 | ) |
|
256 | 1 | ); |
|
257 | 1 | return $this->goHome(); |
|
258 | } |
||
259 | 1 | Yii::$app->session->setFlash( |
|
260 | 1 | 'error', |
|
261 | 1 | Yii::t( |
|
262 | 1 | 'app.messages', |
|
263 | 'An error occurred while sending a message to reset your password' |
||
264 | 1 | ) |
|
265 | 1 | ); |
|
266 | 1 | return $this->goHome(); |
|
267 | } |
||
268 | |||
269 | 8 | return $this->render('requestPasswordResetToken', [ |
|
270 | 8 | 'model' => $model, |
|
271 | 8 | ]); |
|
272 | 6 | } |
|
273 | |||
274 | 8 | public function actionResetPassword($token) |
|
275 | 6 | { |
|
276 | 6 | $model = new ResetPasswordForm(); |
|
277 | |||
278 | 6 | if (!$model->validateToken($token)) { |
|
279 | 2 | Yii::$app->session->setFlash( |
|
280 | 2 | 'error', |
|
281 | 8 | Yii::t('app.messages', 'Invalid link for reset password') |
|
282 | 2 | ); |
|
283 | 2 | return $this->goHome(); |
|
284 | } |
||
285 | |||
286 | 6 | if ($model->load(Yii::$app->request->post()) && |
|
287 | 6 | $model->validate() && |
|
288 | 1 | $model->resetPassword() |
|
289 | 6 | ) { |
|
290 | 3 | Yii::$app->session->setFlash( |
|
291 | 1 | 'success', |
|
292 | 1 | Yii::t('app', 'New password was saved') |
|
293 | 1 | ); |
|
294 | 1 | return $this->goHome(); |
|
295 | } |
||
296 | |||
297 | 6 | return $this->render('resetPassword', [ |
|
298 | 6 | 'model' => $model, |
|
299 | 6 | ]); |
|
300 | 8 | } |
|
301 | |||
302 | 6 | public function actionLogout() |
|
303 | 5 | { |
|
304 | 6 | Yii::$app->user->logout(); |
|
305 | 1 | return $this->goHome(); |
|
306 | } |
||
307 | |||
308 | /** @see commands/MaintenanceController **/ |
||
309 | 2 | public function actionMaintenance() |
|
318 | } |
||
319 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.