Test Failed
Push — master ( a72f1e...02204c )
by Maximo
02:45
created

AuthController::sendEmail()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 6
nop 2
dl 0
loc 31
rs 9.584
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
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)) {
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist on Gewaer\Api\Controllers\AuthController. Since you implemented __get, consider adding a @property annotation.
Loading history...
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
The property config does not exist on Gewaer\Api\Controllers\AuthController. Since you implemented __get, consider adding a @property annotation.
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
Bug Best Practice introduced by
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
The variable $subject does not seem to be defined for all execution paths leading up to this point.
Loading history...
67
                ->content($body)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $body does not seem to be defined for all execution paths leading up to this point.
Loading history...
68
                ->sendNow();
69
        }
70
    }
71
}
72