|
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
|
|
|
* Class AuthController |
|
13
|
|
|
* |
|
14
|
|
|
* @package Gewaer\Api\Controllers |
|
15
|
|
|
* |
|
16
|
|
|
* @property Users $userData |
|
17
|
|
|
* @property Request $request |
|
18
|
|
|
* @property Config $config |
|
19
|
|
|
* @property \Baka\Mail\Message $mail |
|
20
|
|
|
* @property Apps $app |
|
21
|
|
|
*/ |
|
22
|
|
|
class AuthController extends \Baka\Auth\AuthController |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Setup for this controller |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
20 |
|
public function onConstruct() |
|
30
|
|
|
{ |
|
31
|
20 |
|
$this->userLinkedSourcesModel = new UserLinkedSources(); |
|
32
|
20 |
|
$this->userModel = new Users(); |
|
33
|
|
|
|
|
34
|
20 |
|
if (!isset($this->config->jwt)) { |
|
35
|
|
|
throw new ServerErrorHttpException('You need to configure your app JWT'); |
|
36
|
|
|
} |
|
37
|
20 |
|
} |
|
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
|
1 |
|
protected function sendEmail(Users $user, string $type): void |
|
46
|
|
|
{ |
|
47
|
1 |
|
$send = true; |
|
48
|
1 |
|
$subject = null; |
|
49
|
1 |
|
$body = null; |
|
50
|
1 |
|
switch ($type) { |
|
51
|
1 |
|
case 'recover': |
|
52
|
|
|
$recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot; |
|
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
|
|
|
// send email to recover password |
|
56
|
|
|
break; |
|
57
|
1 |
|
case 'reset': |
|
58
|
|
|
$activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key; |
|
59
|
|
|
$subject = _('Password Updated!'); |
|
60
|
|
|
$body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>'); |
|
61
|
|
|
// send email that password was update |
|
62
|
|
|
break; |
|
63
|
|
|
default: |
|
64
|
1 |
|
$send = false; |
|
65
|
1 |
|
break; |
|
66
|
|
|
} |
|
67
|
1 |
|
if ($send) { |
|
68
|
|
|
$this->mail |
|
69
|
|
|
->to($user->email) |
|
70
|
|
|
->subject($subject) |
|
71
|
|
|
->content($body) |
|
72
|
|
|
->sendNow(); |
|
73
|
|
|
} |
|
74
|
1 |
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|