1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Helpers; |
4
|
|
|
|
5
|
|
|
use App\Models\Mail as MailModel; |
6
|
|
|
use App\Singleton; |
7
|
|
|
use Illuminate\Support\Facades\Config; |
8
|
|
|
use Illuminate\Support\Facades\Mail as MailFacade; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Mail. |
12
|
|
|
*/ |
13
|
|
|
final class Mail extends Singleton |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Stored Mail Model. |
17
|
|
|
* |
18
|
|
|
* @var MailModel |
19
|
|
|
*/ |
20
|
|
|
protected $mailModel; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Send an Email. |
24
|
|
|
* |
25
|
|
|
* @param array $configuration |
26
|
|
|
* @param string $view |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail') |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
if (Config::get('mail.enable')) { |
31
|
|
|
MailFacade::send($view, $configuration, function ($message) use ($configuration) { |
32
|
|
|
$message->from(Config::get('mail.from.address'), Config::get('mail.from.name')); |
33
|
|
|
$message->to($configuration['email'])->subject($configuration['subject']); |
34
|
|
|
}); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Store an E-mail. |
40
|
|
|
* |
41
|
|
|
* @param string $email |
42
|
|
|
* @param string $url |
43
|
|
|
* |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function store(string $email, string $url): string |
47
|
|
|
{ |
48
|
|
|
(new MailModel())->store($token = uniqid('HabboMail', true), $url, $email); |
49
|
|
|
|
50
|
|
|
return $token; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Return if Exists E-Mail with that Token. |
55
|
|
|
* |
56
|
|
|
* @param string $token |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function has(string $token) |
61
|
|
|
{ |
62
|
|
|
return $this->get($token) !== null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get an E-mail by Token. |
67
|
|
|
* |
68
|
|
|
* @param string $token |
69
|
|
|
* |
70
|
|
|
* @return MailModel |
71
|
|
|
*/ |
72
|
|
|
public function get(string $token = '') |
73
|
|
|
{ |
74
|
|
|
if ($this->mailModel == null && !empty($token)) { |
75
|
|
|
$mailModel = MailModel::where('token', $token)->where('used', '0')->first(); |
76
|
|
|
|
77
|
|
|
if ($mailModel !== null) { |
78
|
|
|
if (strtotime($mailModel->created_at) + (Config::get('mail.expire') * 24 * 60 * 60) >= time()) { |
79
|
|
|
$this->set($mailModel); |
80
|
|
|
|
81
|
|
|
$this->update(['used' => '1']); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->mailModel; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set Mail Model in Cache. |
91
|
|
|
* |
92
|
|
|
* @param MailModel $model |
93
|
|
|
* |
94
|
|
|
* @return MailModel |
95
|
|
|
*/ |
96
|
|
|
public function set(MailModel $model) |
97
|
|
|
{ |
98
|
|
|
return $this->mailModel = $model; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Update Mail Model Data. |
103
|
|
|
* |
104
|
|
|
* @param array $parameters |
105
|
|
|
* |
106
|
|
|
* @return MailModel |
107
|
|
|
*/ |
108
|
|
|
public function update(array $parameters) |
109
|
|
|
{ |
110
|
|
|
$this->mailModel->update($parameters); |
111
|
|
|
|
112
|
|
|
return $this->mailModel; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.