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