Completed
Push — development ( abd435...15ca07 )
by Claudio
02:24
created

MailController::verify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Mail as MailModel;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Config;
9
use Illuminate\Support\Facades\Mail;
10
use Laravel\Lumen\Routing\Controller as BaseController;
11
12
/**
13
 * Class MailController
14
 * @package App\Http\Controllers
15
 */
16
class MailController extends BaseController
17
{
18
    /**
19
     * Send an Email
20
     *
21
     * @param array $configuration
22
     * @param string $view
23
     */
24
    public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail')
25
    {
26
        if (Config::get('mail.enable'))
27
            Mail::send($view, $configuration, function ($message) use ($configuration) {
28
                $message->from(Config::get('mail.from.address'), Config::get('chocolatey.name'));
29
                $message->to($configuration['mail'])->subject($configuration['subject']);
30
            });
31
    }
32
33
    /**
34
     * Prepare the E-Mail
35
     *
36
     * @param string $email
37
     * @param string $url
38
     * @return string
39
     */
40
    public function prepare(string $email, string $url): string
41
    {
42
        (new MailModel)->store($token = uniqid('HabboMail', true), $url, $email)->save();
43
44
        return $token;
45
    }
46
47
    /**
48
     * Get E-Mail by Controller
49
     *
50
     * @param string $token
51
     * @return object
52
     */
53
    public function getMail(string $token)
54
    {
55
        $mailRequest = MailModel::where('token', $token)->where('used', '0')->first();
56
57
        if ($mailRequest !== null)
58
            $mailRequest->update(['used' => '1']);
59
60
        return $mailRequest;
61
    }
62
}
63