Failed Conditions
Pull Request — master (#18)
by
unknown
08:00
created

AuthController::sendEmail()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 39
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 13.7116

Importance

Changes 0
Metric Value
cc 5
eloc 27
nc 8
nop 2
dl 0
loc 39
ccs 8
cts 27
cp 0.2963
crap 13.7116
rs 9.1768
c 0
b 0
f 0
1
<?php
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 \Baka\Mail\Message $mail
21
 * @property Apps $app
22
 */
23
class AuthController extends \Baka\Auth\AuthController
24
{
25
    /**
26
     * Setup for this controller
27
     *
28
     * @return void
29
     */
30 14
    public function onConstruct()
31
    {
32 14
        $this->userLinkedSourcesModel = new UserLinkedSources();
33 14
        $this->userModel = new Users();
34
35 14
        if (!isset($this->config->jwt)) {
36
            throw new ServerErrorHttpException('You need to configure your app JWT');
37
        }
38 14
    }
39
40
    /**
41
    * Set the email config array we are going to be sending
42
    *
43
    * @param String $emailAction
44
    * @param Users  $user
45
    */
46 1
    protected function sendEmail(BakaUsers $user, string $type): void
47
    {
48 1
        $send = true;
49 1
        $subject = null;
50 1
        $body = null;
51
52 1
        switch ($type) {
53
            case 'recover':
54
                $recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot;
55
56
                $subject = _('Password Recovery');
57
                $body = sprintf(_('Click %shere%s to set a new password for your account.'), '<a href="' . $recoveryLink . '" target="_blank">', '</a>');
58
59
                // send email to recover password
60
                break;
61
            case 'reset':
62
                $activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key;
63
64
                $subject = _('Password Updated!');
65
                $body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>');
66
                // send email that password was update
67
                break;
68
            case 'invite':
69
                //Send invitation link to person
70
                $subject = _('You have been invited!');
71
                $body = sprintf(_('Your have been invite to join our system, use this link to succesfully create your account: %Create account%s'), '<a href="' . $activationUrl . '">', '</a>');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $activationUrl seems to be never defined.
Loading history...
72
73
                break;
74
            default:
75 1
                $send = false;
76 1
                break;
77
        }
78
79 1
        if ($send) {
80
            $this->mail
81
                ->to($user->email)
82
                ->subject($subject)
83
                ->content($body)
84
                ->sendNow();
85
        }
86 1
    }
87
}
88