1 | <?php |
||||
2 | |||||
3 | namespace App\Controller; |
||||
4 | |||||
5 | use App\Form\User\RegistrationForm; |
||||
6 | use App\Form\User\ResetPasswordForm; |
||||
7 | use Bone\Mvc\Registry; |
||||
8 | use Bone\Service\MailService; |
||||
9 | use Del\Common\ContainerService; |
||||
10 | use Del\Exception\EmailLinkException; |
||||
11 | use Del\Exception\UserException; |
||||
12 | use Del\Service\UserService; |
||||
13 | use Del\Value\User\State; |
||||
14 | use Exception; |
||||
15 | use Zend\Diactoros\Response\JsonResponse; |
||||
16 | use Zend\Validator\EmailAddress; |
||||
17 | |||||
18 | /** |
||||
19 | * Class UserController |
||||
20 | * @package App\Controller |
||||
21 | */ |
||||
22 | class UserController extends BaseController |
||||
23 | { |
||||
24 | /** @var UserService */ |
||||
25 | private $userService; |
||||
26 | |||||
27 | 12 | public function init() |
|||
28 | { |
||||
29 | 12 | parent::init(); |
|||
30 | 12 | $c = ContainerService::getInstance()->getContainer(); |
|||
31 | 12 | $this->userService = $c['service.user']; |
|||
32 | 12 | } |
|||
33 | |||||
34 | /** |
||||
35 | * Fetch user details by ID. |
||||
36 | * |
||||
37 | * @OA\Get( |
||||
38 | * path="/user/{id}", |
||||
39 | * tags={"user"}, |
||||
40 | * @OA\Parameter( |
||||
41 | * name="id", |
||||
42 | * in="path", |
||||
43 | * type="integer", |
||||
44 | * description="the type of response", |
||||
45 | * required=false, |
||||
46 | * default=1 |
||||
47 | * ), |
||||
48 | * @OA\Response(response="200", description="Sends user details"), |
||||
49 | * security={ |
||||
50 | * {"clientCredentials": {"admin"}} |
||||
51 | * } |
||||
52 | * ) |
||||
53 | * |
||||
54 | */ |
||||
55 | 1 | public function indexAction() |
|||
56 | { |
||||
57 | 1 | if (!$this->httpMethodCheck('GET')) { return; } |
|||
58 | |||||
59 | 1 | $id = $this->getParam('id'); |
|||
60 | |||||
61 | /** @var UserService $userSvc */ |
||||
62 | 1 | $userSvc = ContainerService::getInstance()->getContainer()['service.user']; |
|||
63 | |||||
64 | 1 | $user = $userSvc->findUserById($id); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
65 | 1 | if (!$user) { |
|||
66 | $this->sendJsonResponse(['error' => 'User not found'], 404); |
||||
67 | return; |
||||
68 | } |
||||
69 | |||||
70 | 1 | $this->sendJsonObjectResponse($user); |
|||
71 | 1 | } |
|||
72 | |||||
73 | |||||
74 | |||||
75 | /** |
||||
76 | * Activate from the email link token. |
||||
77 | * |
||||
78 | * @OA\Get( |
||||
79 | * path="/{locale}/user/activate/{email}/{token}", |
||||
80 | * tags={"user_registration"}, |
||||
81 | * @OA\Response(response="200", description="Registers a new unactivated user"), |
||||
82 | * @OA\Parameter( |
||||
83 | * name="locale", |
||||
84 | * in="path", |
||||
85 | * type="string", |
||||
86 | * description="the locale to use", |
||||
87 | * required=true, |
||||
88 | * default="en_GB" |
||||
89 | * ), |
||||
90 | * @OA\Parameter( |
||||
91 | * name="email", |
||||
92 | * in="path", |
||||
93 | * type="string", |
||||
94 | * description="the users email", |
||||
95 | * required=true, |
||||
96 | * default="[email protected]" |
||||
97 | * ), |
||||
98 | * @OA\Parameter( |
||||
99 | * name="token", |
||||
100 | * in="path", |
||||
101 | * type="string", |
||||
102 | * description="the email link token", |
||||
103 | * required=true, |
||||
104 | * default="r4nd0mT0k3n" |
||||
105 | * ) |
||||
106 | * ) |
||||
107 | * @throws Exception |
||||
108 | */ |
||||
109 | 6 | public function activateAction() |
|||
110 | { |
||||
111 | 6 | if (!$this->httpMethodCheck('GET')) { return; } |
|||
112 | |||||
113 | 6 | $email = $this->getParam('email'); |
|||
114 | 6 | $token = $this->getParam('token'); |
|||
115 | |||||
116 | 6 | $userService = $this->userService; |
|||
117 | |||||
118 | try { |
||||
119 | |||||
120 | 6 | $link = $userService->findEmailLink($email, $token); |
|||
121 | |||||
122 | 2 | $user = $link->getUser(); |
|||
123 | 2 | $user->setState(new State(State::STATE_ACTIVATED)); |
|||
124 | 2 | $userService->saveUser($user); |
|||
125 | 2 | $userService->deleteEmailLink($link); |
|||
126 | 2 | $data = ['success' => true]; |
|||
127 | 2 | $code = 200; |
|||
128 | |||||
129 | 4 | } catch (EmailLinkException $e) { |
|||
130 | 4 | switch ($e->getMessage()) { |
|||
131 | 4 | case EmailLinkException::LINK_EXPIRED: |
|||
132 | 3 | case EmailLinkException::LINK_NO_MATCH: |
|||
133 | $data = [ |
||||
134 | 1 | 'success' => false, |
|||
135 | 1 | 'error' => $e->getMessage(), |
|||
136 | ]; |
||||
137 | 1 | $code = 403; |
|||
138 | 1 | break; |
|||
139 | 3 | case EmailLinkException::LINK_NOT_FOUND: |
|||
140 | $data = [ |
||||
141 | 3 | 'success' => false, |
|||
142 | 3 | 'error' => $e->getMessage(), |
|||
143 | ]; |
||||
144 | 3 | $code = 404; |
|||
145 | 3 | break; |
|||
146 | default: |
||||
147 | $data = [ |
||||
148 | 'success' => false, |
||||
149 | 'error' => $e->getMessage(), |
||||
150 | ]; |
||||
151 | $code = 500; |
||||
152 | break; |
||||
153 | } |
||||
154 | } |
||||
155 | |||||
156 | 6 | $this->sendJsonResponse($data, $code); |
|||
157 | 6 | } |
|||
158 | |||||
159 | |||||
160 | /** |
||||
161 | * Refresh the activation email link token. |
||||
162 | * |
||||
163 | * @OA\Get( |
||||
164 | * path="/{locale}/user/activate/resend/{email}", |
||||
165 | * tags={"user_registration"}, |
||||
166 | * @OA\Parameter( |
||||
167 | * name="locale", |
||||
168 | * in="path", |
||||
169 | * type="string", |
||||
170 | * description="the locale to use", |
||||
171 | * required=true, |
||||
172 | * default="en_GB" |
||||
173 | * ), |
||||
174 | * @OA\Parameter( |
||||
175 | * name="email", |
||||
176 | * in="path", |
||||
177 | * type="string", |
||||
178 | * description="the email of the user registering", |
||||
179 | * required=true, |
||||
180 | * default="[email protected]" |
||||
181 | * ), |
||||
182 | * @OA\Response(response="200", description="Sends email link details") |
||||
183 | * ) |
||||
184 | * @throws Exception |
||||
185 | */ |
||||
186 | 2 | public function resendActivationAction() |
|||
187 | { |
||||
188 | 2 | if (!$this->httpMethodCheck('GET')) { return; } |
|||
189 | |||||
190 | 2 | $email = $this->getParam('email'); |
|||
191 | |||||
192 | 2 | $user = $this->userService->findUserByEmail($email); |
|||
193 | 2 | if (!$user) { |
|||
194 | $this->sendJsonResponse(['error' => UserException::USER_NOT_FOUND], 404); |
||||
195 | return; |
||||
196 | } |
||||
197 | |||||
198 | 2 | if ($user->getState()->getValue() == State::STATE_ACTIVATED) { |
|||
199 | 1 | $this->sendJsonResponse(['error' => UserException::USER_ACTIVATED], 400); |
|||
200 | 1 | return; |
|||
201 | } |
||||
202 | |||||
203 | 1 | $link = $this->userService->generateEmailLink($user); |
|||
204 | |||||
205 | 1 | $mail = $this->getMailService(); |
|||
206 | 1 | $env = $this->getServerEnvironment(); |
|||
207 | 1 | $email = $user->getEmail(); |
|||
208 | 1 | $token = $link->getToken(); |
|||
209 | |||||
210 | 1 | $message = $this->getViewEngine()->render('emails/user_registration/user_registration', [ |
|||
211 | 1 | 'siteUrl' => $env->getSiteURL(), |
|||
212 | 1 | 'activationLink' => '/' . $this->getParam('locale') . '/user/activate/' . $email . '/' . $token, |
|||
213 | ]); |
||||
214 | |||||
215 | 1 | $mail->setFrom('noreply@' . $env->getServerName()) |
|||
216 | 1 | ->setTo($user->getEmail()) |
|||
217 | 1 | ->setSubject($this->getTranslator() |
|||
218 | 1 | ->translate('email.user.register.thankswith') . ' ' . Registry::ahoy()->get('site')['name']) |
|||
219 | 1 | ->setMessage($message) |
|||
220 | 1 | ->send(); |
|||
221 | |||||
222 | |||||
223 | 1 | $this->sendJsonObjectResponse($link); |
|||
224 | 1 | } |
|||
225 | |||||
226 | /** |
||||
227 | * Get a lost password email link token. |
||||
228 | * |
||||
229 | * @OA\Get( |
||||
230 | * path="/{locale}/user/lost-password/{email}", |
||||
231 | * tags={"user_registration"}, |
||||
232 | * @OA\Parameter( |
||||
233 | * name="locale", |
||||
234 | * in="path", |
||||
235 | * type="string", |
||||
236 | * description="the locale to use", |
||||
237 | * required=true, |
||||
238 | * default="en_GB" |
||||
239 | * ), |
||||
240 | * @OA\Parameter( |
||||
241 | * name="email", |
||||
242 | * in="path", |
||||
243 | * type="string", |
||||
244 | * description="the email of the user", |
||||
245 | * required=true, |
||||
246 | * default="[email protected]" |
||||
247 | * ), |
||||
248 | * @OA\Response(response="200", description="Sends email link details") |
||||
249 | * ) |
||||
250 | * @throws Exception |
||||
251 | */ |
||||
252 | 3 | public function lostPasswordAction() |
|||
253 | { |
||||
254 | 3 | if (!$this->httpMethodCheck('GET')) { return; } |
|||
255 | |||||
256 | 3 | $email = $this->getParam('email'); |
|||
257 | |||||
258 | 3 | $user = $this->userService->findUserByEmail($email); |
|||
259 | 3 | if (!$user) { |
|||
260 | 1 | $this->sendJsonResponse(['error' => UserException::USER_NOT_FOUND], 404); |
|||
261 | 1 | return; |
|||
262 | } |
||||
263 | |||||
264 | 2 | if ($user->getState()->getValue() == State::STATE_UNACTIVATED) { |
|||
265 | 1 | $this->sendJsonResponse(['error' => UserException::USER_UNACTIVATED], 400); |
|||
266 | 1 | return; |
|||
267 | } |
||||
268 | |||||
269 | 1 | $link = $this->userService->generateEmailLink($user); |
|||
270 | 1 | $this->sendJsonObjectResponse($link); |
|||
271 | 1 | } |
|||
272 | |||||
273 | /** |
||||
274 | * Register as a new user. Returns an email link token. |
||||
275 | * |
||||
276 | * @OA\Post( |
||||
277 | * path="/{locale}/user/register", |
||||
278 | * tags={"user_registration"}, |
||||
279 | * @OA\Response(response="200", description="Registers a new unactivated user"), |
||||
280 | * @OA\Parameter( |
||||
281 | * name="locale", |
||||
282 | * in="path", |
||||
283 | * type="string", |
||||
284 | * description="the locale to use", |
||||
285 | * required=true, |
||||
286 | * default="en_GB" |
||||
287 | * ), |
||||
288 | * @OA\Parameter( |
||||
289 | * name="email", |
||||
290 | * in="formData", |
||||
291 | * type="string", |
||||
292 | * description="the users email", |
||||
293 | * required=true, |
||||
294 | * default="[email protected]" |
||||
295 | * ), |
||||
296 | * @OA\Parameter( |
||||
297 | * name="password", |
||||
298 | * in="formData", |
||||
299 | * type="string", |
||||
300 | * description="a password for the user", |
||||
301 | * required=true, |
||||
302 | * default="password" |
||||
303 | * ), |
||||
304 | * @OA\Parameter( |
||||
305 | * name="confirm", |
||||
306 | * in="formData", |
||||
307 | * type="string", |
||||
308 | * description="password confirmation", |
||||
309 | * required=true, |
||||
310 | * default="password" |
||||
311 | * ) |
||||
312 | * ) |
||||
313 | * @throws Exception |
||||
314 | */ |
||||
315 | 7 | public function registerAction() |
|||
316 | { |
||||
317 | 7 | if (!$this->httpMethodCheck('POST')) { return null; } |
|||
318 | |||||
319 | 7 | $form = new RegistrationForm('register'); |
|||
320 | |||||
321 | 7 | if ($this->getRequest()->getMethod() == 'POST') { |
|||
322 | |||||
323 | 7 | $formData = $this->getRequest()->getParsedBody(); |
|||
324 | 7 | $form->populate($formData); |
|||
0 ignored issues
–
show
It seems like
$formData can also be of type null and object ; however, parameter $data of Del\Form\AbstractForm::populate() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
325 | |||||
326 | 7 | if ($form->isValid()) { |
|||
327 | 7 | $data = $form->getValues(); |
|||
328 | try { |
||||
329 | 7 | $user = $this->userService->registerUser($data); |
|||
330 | 7 | $link = $this->userService->generateEmailLink($user); |
|||
331 | 7 | $mail = $this->getMailService(); |
|||
332 | 7 | $env = $this->getServerEnvironment(); |
|||
333 | 7 | $email = $user->getEmail(); |
|||
334 | 7 | $token = $link->getToken(); |
|||
335 | |||||
336 | 7 | $message = $this->getViewEngine()->render('emails/user_registration/user_registration', [ |
|||
337 | 7 | 'siteUrl' => $env->getSiteURL(), |
|||
338 | 7 | 'activationLink' => '/' . $this->getParam('locale') . '/activate-user-account/' . $email . '/' . $token, |
|||
339 | ]); |
||||
340 | |||||
341 | 7 | $mail->setFrom('noreply@' . $env->getServerName()) |
|||
342 | 7 | ->setTo($user->getEmail()) |
|||
343 | 7 | ->setSubject($this->getTranslator() |
|||
344 | 7 | ->translate('email.user.register.thankswith') . ' ' . Registry::ahoy()->get('site')['name']) |
|||
345 | 7 | ->setMessage($message) |
|||
346 | 7 | ->send(); |
|||
347 | 7 | $this->sendJsonObjectResponse($link); |
|||
348 | |||||
349 | } catch (UserException $e) { |
||||
350 | |||||
351 | switch ($e->getMessage()) { |
||||
352 | case UserException::USER_EXISTS: |
||||
353 | case UserException::WRONG_PASSWORD: |
||||
354 | throw new Exception($e->getMessage(), 400); |
||||
355 | break; |
||||
356 | } |
||||
357 | throw $e; |
||||
358 | } |
||||
359 | } else { |
||||
360 | throw new Exception('Invalid request data', 400); |
||||
361 | } |
||||
362 | |||||
363 | } |
||||
364 | 7 | } |
|||
365 | |||||
366 | |||||
367 | |||||
368 | /** |
||||
369 | * Resets the users password. Requires an email link token. |
||||
370 | * |
||||
371 | * @OA\Post( |
||||
372 | * path="/{locale}/user/reset-password/{email}/{token}", |
||||
373 | * tags={"user_registration"}, |
||||
374 | * @OA\Response(response="200", description="Resets a users email"), |
||||
375 | * @OA\Parameter( |
||||
376 | * name="locale", |
||||
377 | * in="path", |
||||
378 | * type="string", |
||||
379 | * description="the locale to use", |
||||
380 | * required=true, |
||||
381 | * default="en_GB" |
||||
382 | * ), |
||||
383 | * @OA\Parameter( |
||||
384 | * name="email", |
||||
385 | * in="path", |
||||
386 | * type="string", |
||||
387 | * description="the email of the user", |
||||
388 | * required=true, |
||||
389 | * default="[email protected]" |
||||
390 | * ), |
||||
391 | * @OA\Parameter( |
||||
392 | * name="token", |
||||
393 | * in="path", |
||||
394 | * type="string", |
||||
395 | * description="the email link token", |
||||
396 | * required=true, |
||||
397 | * default="r4nd0mT0k3n" |
||||
398 | * ), |
||||
399 | * @OA\Parameter( |
||||
400 | * name="password", |
||||
401 | * in="formData", |
||||
402 | * type="string", |
||||
403 | * description="a password for the user", |
||||
404 | * required=true, |
||||
405 | * default="password" |
||||
406 | * ), |
||||
407 | * @OA\Parameter( |
||||
408 | * name="confirm", |
||||
409 | * in="formData", |
||||
410 | * type="string", |
||||
411 | * description="password confirmation", |
||||
412 | * required=true, |
||||
413 | * default="password" |
||||
414 | * ) |
||||
415 | * ) |
||||
416 | * @throws Exception |
||||
417 | */ |
||||
418 | public function resetPassAction() |
||||
419 | { |
||||
420 | if (!$this->httpMethodCheck('POST')) { return; } |
||||
421 | |||||
422 | $email = $this->getParam('email'); |
||||
423 | $token = $this->getParam('token'); |
||||
424 | |||||
425 | $user = $this->userService->findUserByEmail($email); |
||||
426 | if (!$user) { |
||||
427 | $this->sendJsonResponse(['error' => UserException::USER_NOT_FOUND], 404); |
||||
428 | return; |
||||
429 | } |
||||
430 | |||||
431 | try { |
||||
432 | $link = $this->userService->findEmailLink($email, $token); |
||||
433 | } catch (EmailLinkException $e) { |
||||
434 | $code = $e->getMessage() == EmailLinkException::LINK_EXPIRED ? 400 : 404; |
||||
435 | $this->sendJsonResponse(['error' => $e->getMessage(), $code]); |
||||
436 | return; |
||||
437 | } |
||||
438 | |||||
439 | $form = new ResetPasswordForm('reset-pass'); |
||||
440 | |||||
441 | $data = $this->getRequest()->getParsedBody(); |
||||
442 | |||||
443 | $form->populate($data); |
||||
0 ignored issues
–
show
It seems like
$data can also be of type null and object ; however, parameter $data of Del\Form\AbstractForm::populate() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
444 | |||||
445 | if ($form->isValid()) { |
||||
446 | |||||
447 | if ($data['password'] == $data['confirm']) { |
||||
448 | $this->userService->changePassword($user, $data['password']); |
||||
449 | $this->userService->deleteEmailLink($link); |
||||
450 | $this->sendJsonResponse(['success' => 'Password successfully changed']); |
||||
451 | return; |
||||
452 | } else { |
||||
453 | $this->sendJsonResponse(['error' => 'Passwords did not match, please try again.'], 400); |
||||
454 | } |
||||
455 | } else { |
||||
456 | $errors = []; |
||||
457 | $fields = $form->getFields(); |
||||
458 | foreach ($fields as $field) { |
||||
459 | $validators = $field->getValidators(); |
||||
460 | foreach ($validators as $validator) { |
||||
461 | $errors[$field->getName()] = $validator->getMessages(); |
||||
462 | } |
||||
463 | } |
||||
464 | $this->sendJsonResponse(['error' => $errors], 400); |
||||
465 | } |
||||
466 | } |
||||
467 | |||||
468 | |||||
469 | /** |
||||
470 | * @OA\Post( |
||||
471 | * path="/{locale}/me/change-password/", |
||||
472 | * tags={"user_profile"}, |
||||
473 | * @OA\Response(response="200", description="Changes a users password."), |
||||
474 | * @OA\Parameter( |
||||
475 | * name="locale", |
||||
476 | * in="path", |
||||
477 | * type="string", |
||||
478 | * description="the locale to use", |
||||
479 | * required=true, |
||||
480 | * default="en_GB" |
||||
481 | * ), |
||||
482 | * @OA\Parameter( |
||||
483 | * name="email", |
||||
484 | * in="path", |
||||
485 | * type="string", |
||||
486 | * description="the email of the user", |
||||
487 | * required=true, |
||||
488 | * default="[email protected]" |
||||
489 | * ), |
||||
490 | * @OA\Parameter( |
||||
491 | * name="token", |
||||
492 | * in="path", |
||||
493 | * type="formData", |
||||
494 | * description="the email link token", |
||||
495 | * required=true, |
||||
496 | * default="r4nd0mT0k3n" |
||||
497 | * ), |
||||
498 | * @OA\Parameter( |
||||
499 | * name="password", |
||||
500 | * in="formData", |
||||
501 | * type="string", |
||||
502 | * description="a password for the user", |
||||
503 | * required=true, |
||||
504 | * default="password" |
||||
505 | * ), |
||||
506 | * @OA\Parameter( |
||||
507 | * name="confirm", |
||||
508 | * in="formData", |
||||
509 | * type="string", |
||||
510 | * description="password confirmation", |
||||
511 | * required=true, |
||||
512 | * default="password" |
||||
513 | * ) |
||||
514 | * ) |
||||
515 | * @throws Exception |
||||
516 | */ |
||||
517 | public function changePassAction() |
||||
518 | { |
||||
519 | // $request = $this->getRequest(); |
||||
520 | // |
||||
521 | // $form = new Application_Form_ChangePass(); |
||||
522 | // |
||||
523 | // if ($request->isPost()) { |
||||
524 | // |
||||
525 | // $data = $request->getPost(); |
||||
526 | // |
||||
527 | // if ($form->isValid($data)) { |
||||
528 | // |
||||
529 | // $oldPassword = $form->getValue('oldPassword'); |
||||
530 | // $password = $form->getValue('password'); |
||||
531 | // $confirm = $form->getValue('confirm'); |
||||
532 | // |
||||
533 | // if ($password != $confirm) { |
||||
534 | // |
||||
535 | // $this->view->message = ['Your new passwords didn\'t match!','danger']; |
||||
536 | // |
||||
537 | // } else { |
||||
538 | // |
||||
539 | // $user = $this->getUserService()->findUserById(Zend_Auth::getInstance()->getIdentity()); |
||||
540 | // |
||||
541 | // if($this->getUserService()->checkPassword($user, $oldPassword)) { |
||||
542 | // |
||||
543 | // $this->getUserService()->changePassword($user, $password); |
||||
544 | // $this->view->message = ['Password successfully updated. Click here to <a href ="/">return</a>.','success']; |
||||
545 | // return; |
||||
546 | // |
||||
547 | // } else { |
||||
548 | // |
||||
549 | // $this->view->message = ['Your password was wrong!','danger']; |
||||
550 | // |
||||
551 | // } |
||||
552 | // } |
||||
553 | // } |
||||
554 | // } |
||||
555 | // $this->view->form = $form; |
||||
556 | } |
||||
557 | |||||
558 | /** |
||||
559 | * @OA\Post( |
||||
560 | * path="/{locale}/me/change-email/", |
||||
561 | * tags={"user_profile"}, |
||||
562 | * @OA\Response(response="200", description="Changes a users email."), |
||||
563 | * @OA\Parameter( |
||||
564 | * name="locale", |
||||
565 | * in="path", |
||||
566 | * type="string", |
||||
567 | * description="the locale to use", |
||||
568 | * required=true, |
||||
569 | * default="en_GB" |
||||
570 | * ), |
||||
571 | * @OA\Parameter( |
||||
572 | * name="email", |
||||
573 | * in="path", |
||||
574 | * type="string", |
||||
575 | * description="the email of the user", |
||||
576 | * required=true, |
||||
577 | * default="[email protected]" |
||||
578 | * ), |
||||
579 | * @OA\Parameter( |
||||
580 | * name="token", |
||||
581 | * in="path", |
||||
582 | * type="formData", |
||||
583 | * description="the email link token", |
||||
584 | * required=true, |
||||
585 | * default="r4nd0mT0k3n" |
||||
586 | * ), |
||||
587 | * @OA\Parameter( |
||||
588 | * name="password", |
||||
589 | * in="formData", |
||||
590 | * type="string", |
||||
591 | * description="a password for the user", |
||||
592 | * required=true, |
||||
593 | * default="password" |
||||
594 | * ), |
||||
595 | * @OA\Parameter( |
||||
596 | * name="confirm", |
||||
597 | * in="formData", |
||||
598 | * type="string", |
||||
599 | * description="password confirmation", |
||||
600 | * required=true, |
||||
601 | * default="password" |
||||
602 | * ) |
||||
603 | * ) |
||||
604 | * @throws Exception |
||||
605 | */ |
||||
606 | public function changeEmailAction() |
||||
607 | { |
||||
608 | // /* @var $request Zend_Controller_Request_Http */ |
||||
609 | // $request = $this->getRequest(); |
||||
610 | // |
||||
611 | // $user = $this->getUserService()->findUserById(Zend_Auth::getInstance()->getIdentity()); |
||||
612 | // |
||||
613 | // $form = new Application_Form_ChangeEmail(); |
||||
614 | // |
||||
615 | // if ($request->isPost()) { |
||||
616 | // |
||||
617 | // $data = $request->getPost(); |
||||
618 | // |
||||
619 | // if ($form->isValid($data)) { |
||||
620 | // |
||||
621 | // $newEmail = $form->getValue('email'); |
||||
622 | // $password = $form->getValue('password'); |
||||
623 | // |
||||
624 | // $existing = $this->getUserService()->findUserByEmail($newEmail); |
||||
625 | // if($existing) { |
||||
626 | // |
||||
627 | // $this->view->message = ['This email is already registered with a Cloud Tax Return account.','danger']; |
||||
628 | // return; |
||||
629 | // } |
||||
630 | // |
||||
631 | // if ($this->getUserService()->checkPassword($user, $password)) { |
||||
632 | // |
||||
633 | // $link = $this->getUserService()->generateEmailLink($user); |
||||
634 | // |
||||
635 | // try { |
||||
636 | // |
||||
637 | // $siteURL = SITE_URL; |
||||
638 | // $currentEmail = $user->getEmail(); |
||||
639 | // $token = $link->getToken(); |
||||
640 | // |
||||
641 | // $message = |
||||
642 | // <<<END |
||||
643 | // You have requested to change the login email for your Cloud Tax Return account to $newEmail. Click on the link below to confirm this change. |
||||
644 | // You can ignore this email if you do not wish to change your address.<br / <br /> |
||||
645 | //<a href="$siteURL/reset-email/$currentEmail/$newEmail/$token">Switch to my new email address.</a>. |
||||
646 | //END; |
||||
647 | // |
||||
648 | // /** @var Mail $emailService */ |
||||
649 | // $mail = new Mail(); |
||||
650 | // $mail->setFrom('[email protected]') |
||||
651 | // ->setTo($currentEmail) |
||||
652 | // ->setSubject('Change your email address on Cloud Tax Return.') |
||||
653 | // ->setHeader(Template::getHeader()) |
||||
654 | // ->setFooter(Template::getFooter()) |
||||
655 | // ->setMessage($message) |
||||
656 | // ->send(); |
||||
657 | // |
||||
658 | // $this->view->message = ['Please check your email for a link to activate your new address.','info']; |
||||
659 | // $this->view->form = null; |
||||
660 | // |
||||
661 | // } catch (Exception $e) { |
||||
662 | // $this->view->message = ['We were unable to send your e-mail confirmation. Please contact '.$this->config->email->support.'.','danger']; |
||||
663 | // } |
||||
664 | // |
||||
665 | // } else { |
||||
666 | // $this->view->message = ['Your password was wrong','danger']; |
||||
667 | // } |
||||
668 | // |
||||
669 | // } |
||||
670 | // } |
||||
671 | // $this->view->form = $form; |
||||
672 | } |
||||
673 | |||||
674 | |||||
675 | /** |
||||
676 | * @OA\Post( |
||||
677 | * path="/{locale}/me/reset-email/", |
||||
678 | * tags={"user_profile"}, |
||||
679 | * @OA\Response(response="200", description="Resets the users email."), |
||||
680 | * @OA\Parameter( |
||||
681 | * name="locale", |
||||
682 | * in="path", |
||||
683 | * type="string", |
||||
684 | * description="the locale to use", |
||||
685 | * required=true, |
||||
686 | * default="en_GB" |
||||
687 | * ), |
||||
688 | * @OA\Parameter( |
||||
689 | * name="email", |
||||
690 | * in="formData", |
||||
691 | * type="string", |
||||
692 | * description="the email of the user", |
||||
693 | * required=true, |
||||
694 | * default="[email protected]" |
||||
695 | * ), |
||||
696 | * @OA\Parameter( |
||||
697 | * name="newemail", |
||||
698 | * in="formData", |
||||
699 | * type="string", |
||||
700 | * description="password confirmation", |
||||
701 | * required=true, |
||||
702 | * default="password" |
||||
703 | * ), |
||||
704 | * @OA\Parameter( |
||||
705 | * name="token", |
||||
706 | * in="path", |
||||
707 | * type="string", |
||||
708 | * description="the email link token", |
||||
709 | * required=true, |
||||
710 | * default="r4nd0mT0k3n" |
||||
711 | * ), |
||||
712 | * @OA\Parameter( |
||||
713 | * name="password", |
||||
714 | * in="formData", |
||||
715 | * type="string", |
||||
716 | * description="a password for the user", |
||||
717 | * required=true, |
||||
718 | * default="password" |
||||
719 | * ), |
||||
720 | * ) |
||||
721 | * @throws Exception |
||||
722 | */ |
||||
723 | public function resetEmailAction() |
||||
724 | { |
||||
725 | // $email = $this->_request->getParam('email'); |
||||
726 | // $newEmail = $this->_request->getParam('newemail'); |
||||
727 | // $token = $this->_request->getParam('token'); |
||||
728 | // |
||||
729 | // try { |
||||
730 | // |
||||
731 | // $link = $this->getUserService()->findEmailLink($email, $token); |
||||
732 | // $user = $link->getUser(); |
||||
733 | // $user->setEmail($newEmail); |
||||
734 | // $this->getUserService()->saveUser($user); |
||||
735 | // $this->getUserService()->deleteEmailLink($link); |
||||
736 | // $this->view->message = ['You have switched your email address. Please log in with '.$newEmail.' from now on.', 'success']; |
||||
737 | // |
||||
738 | // } catch (EmailLinkException $e) { |
||||
739 | // $this->view->message = [$e->getMessage(), 'danger']; |
||||
740 | // return; |
||||
741 | // } catch (Exception $e) { |
||||
742 | // throw $e; |
||||
743 | // } |
||||
744 | } |
||||
745 | } |
||||
746 |