|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Xetaravel\Notifications\Auth; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Illuminate\Bus\Queueable; |
|
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
10
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
|
11
|
|
|
use Illuminate\Notifications\Notification; |
|
12
|
|
|
use Illuminate\Support\Carbon; |
|
13
|
|
|
use Illuminate\Support\Facades\Config; |
|
14
|
|
|
use Illuminate\Support\Facades\URL; |
|
15
|
|
|
|
|
16
|
|
|
class VerifyEmail extends Notification implements ShouldQueue |
|
17
|
|
|
{ |
|
18
|
|
|
use Queueable; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The callback that should be used to build the mail message. |
|
22
|
|
|
* |
|
23
|
|
|
* @var Closure|null |
|
24
|
|
|
*/ |
|
25
|
|
|
public static ?Closure $toMailCallback = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get the verification URL for the given notifiable. |
|
29
|
|
|
* |
|
30
|
|
|
* @param mixed $notifiable |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function verificationUrl(mixed $notifiable): string |
|
34
|
|
|
{ |
|
35
|
|
|
return URL::temporarySignedRoute( |
|
36
|
|
|
'auth.verification.verify', |
|
37
|
|
|
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), |
|
38
|
|
|
[ |
|
39
|
|
|
'id' => $notifiable->getKey(), |
|
40
|
|
|
'hash' => base64_encode($notifiable->getEmailForVerification()), |
|
41
|
|
|
] |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Set a callback that should be used when building the notification mail message. |
|
47
|
|
|
* |
|
48
|
|
|
* @param Closure $callback |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function toMailUsing(Closure $callback): void |
|
53
|
|
|
{ |
|
54
|
|
|
static::$toMailCallback = $callback; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get the notification's channels. |
|
59
|
|
|
* |
|
60
|
|
|
* @param mixed $notifiable |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function via(mixed $notifiable): array |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
return ['mail']; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Build the mail representation of the notification. |
|
71
|
|
|
* |
|
72
|
|
|
* @param mixed $notifiable |
|
73
|
|
|
* @return MailMessage |
|
74
|
|
|
*/ |
|
75
|
|
|
public function toMail(mixed $notifiable): MailMessage |
|
76
|
|
|
{ |
|
77
|
|
|
$verificationUrl = $this->verificationUrl($notifiable); |
|
78
|
|
|
|
|
79
|
|
|
if (static::$toMailCallback) { |
|
80
|
|
|
return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return (new MailMessage()) |
|
84
|
|
|
->level('primary') |
|
85
|
|
|
->subject('Email Verification') |
|
86
|
|
|
->line('Please click the button below to verify your email address:') |
|
87
|
|
|
->action('Verify my Email', $verificationUrl) |
|
88
|
|
|
->line('If you have not created an account on the ' . config('app.name') . ' site, ' . |
|
89
|
|
|
'no further action is required and you can ignore this email.') |
|
90
|
|
|
->from(config('xetaravel.site.contact_email'), config('app.name')); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.