1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gewaer\Api\Controllers; |
||
6 | |||
7 | use Gewaer\Models\Users; |
||
8 | use Baka\Auth\Models\Users as BakaUsers; |
||
9 | use Gewaer\Models\UserLinkedSources; |
||
10 | use Gewaer\Exception\ServerErrorHttpException; |
||
11 | |||
12 | /** |
||
13 | * Class AuthController |
||
14 | * |
||
15 | * @package Gewaer\Api\Controllers |
||
16 | * |
||
17 | * @property Users $userData |
||
18 | * @property Request $request |
||
19 | * @property Config $config |
||
20 | * @property \Phalcon\Mailer\Message $mail |
||
21 | */ |
||
22 | class AuthController extends \Baka\Auth\AuthController |
||
23 | { |
||
24 | /** |
||
25 | * Setup for this controller |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 1 | public function onConstruct() |
|
30 | { |
||
31 | 1 | $this->userLinkedSourcesModel = new UserLinkedSources(); |
|
32 | 1 | $this->userModel = new Users(); |
|
33 | |||
34 | 1 | if (!isset($this->config->jwt)) { |
|
35 | throw new ServerErrorHttpException('You need to configure your app JWT'); |
||
36 | } |
||
37 | 1 | } |
|
38 | |||
39 | /** |
||
40 | * Set the email config array we are going to be sending |
||
41 | * |
||
42 | * @param String $emailAction |
||
43 | * @param Users $user |
||
44 | */ |
||
45 | protected function sendEmail(BakaUsers $user, string $type): void |
||
46 | { |
||
47 | $send = true; |
||
48 | |||
49 | switch ($type) { |
||
50 | case 'recover': |
||
51 | $recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot; |
||
52 | |||
53 | $subject = _('Password Recovery'); |
||
54 | $body = sprintf(_('Click %shere%s to set a new password for your account.'), '<a href="' . $recoveryLink . '" target="_blank">', '</a>'); |
||
55 | |||
56 | // send email to recover password |
||
57 | break; |
||
58 | case 'reset': |
||
59 | $activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key; |
||
60 | |||
61 | $subject = _('Password Updated!'); |
||
62 | $body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>'); |
||
63 | // send email that password was update |
||
64 | break; |
||
65 | default: |
||
66 | $send = false; |
||
67 | break; |
||
68 | } |
||
69 | |||
70 | if ($send) { |
||
71 | $this->mail |
||
72 | ->to($user->email) |
||
73 | ->subject($subject) |
||
74 | ->content($body) |
||
75 | ->sendNow(); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 |