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 | * Base controller |
||
14 | * |
||
15 | */ |
||
16 | class AuthController extends \Baka\Auth\AuthController |
||
17 | { |
||
18 | /** |
||
19 | * Setup for this controller |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | 1 | public function onConstruct() |
|
24 | { |
||
25 | 1 | $this->userLinkedSourcesModel = new UserLinkedSources(); |
|
26 | 1 | $this->userModel = new Users(); |
|
27 | |||
28 | 1 | if (!isset($this->config->jwt)) { |
|
29 | throw new ServerErrorHttpException('You need to configure your app JWT'); |
||
30 | } |
||
31 | 1 | } |
|
32 | |||
33 | /** |
||
34 | * Set the email config array we are going to be sending |
||
35 | * |
||
36 | * @param String $emailAction |
||
37 | * @param Users $user |
||
38 | */ |
||
39 | protected function sendEmail(BakaUsers $user, string $type): void |
||
40 | { |
||
41 | $send = true; |
||
42 | |||
43 | switch ($type) { |
||
44 | case 'recover': |
||
45 | $recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot; |
||
46 | |||
47 | $subject = _('Password Recovery'); |
||
48 | $body = sprintf(_('Click %shere%s to set a new password for your account.'), '<a href="' . $recoveryLink . '" target="_blank">', '</a>'); |
||
49 | |||
50 | // send email to recover password |
||
51 | break; |
||
52 | case 'reset': |
||
53 | $activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key; |
||
54 | |||
55 | $subject = _('Password Updated!'); |
||
56 | $body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>'); |
||
57 | // send email that password was update |
||
58 | break; |
||
59 | default: |
||
60 | $send = false; |
||
61 | break; |
||
62 | } |
||
63 | |||
64 | if ($send) { |
||
65 | $this->mail |
||
66 | ->to($user->email) |
||
67 | ->subject($subject) |
||
68 | ->content($body) |
||
69 | ->sendNow(); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 |