| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Auth\Notifications;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
6 |
use Illuminate\Notifications\Notification;
|
|
|
7 |
use Illuminate\Support\Carbon;
|
|
|
8 |
use Illuminate\Support\Facades\Config;
|
|
|
9 |
use Illuminate\Support\Facades\Lang;
|
|
|
10 |
use Illuminate\Support\Facades\URL;
|
|
|
11 |
|
|
|
12 |
class VerifyEmail extends Notification
|
|
|
13 |
{
|
|
|
14 |
/**
|
|
|
15 |
* The callback that should be used to create the verify email URL.
|
|
|
16 |
*
|
|
|
17 |
* @var \Closure|null
|
|
|
18 |
*/
|
|
|
19 |
public static $createUrlCallback;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* The callback that should be used to build the mail message.
|
|
|
23 |
*
|
|
|
24 |
* @var \Closure|null
|
|
|
25 |
*/
|
|
|
26 |
public static $toMailCallback;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Get the notification's channels.
|
|
|
30 |
*
|
|
|
31 |
* @param mixed $notifiable
|
|
|
32 |
* @return array|string
|
|
|
33 |
*/
|
|
|
34 |
public function via($notifiable)
|
|
|
35 |
{
|
|
|
36 |
return ['mail'];
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Build the mail representation of the notification.
|
|
|
41 |
*
|
|
|
42 |
* @param mixed $notifiable
|
|
|
43 |
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
44 |
*/
|
|
|
45 |
public function toMail($notifiable)
|
|
|
46 |
{
|
|
|
47 |
$verificationUrl = $this->verificationUrl($notifiable);
|
|
|
48 |
|
|
|
49 |
if (static::$toMailCallback) {
|
|
|
50 |
return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
return $this->buildMailMessage($verificationUrl);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Get the verify email notification mail message for the given URL.
|
|
|
58 |
*
|
|
|
59 |
* @param string $url
|
|
|
60 |
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
61 |
*/
|
|
|
62 |
protected function buildMailMessage($url)
|
|
|
63 |
{
|
|
|
64 |
return (new MailMessage)
|
|
|
65 |
->subject(Lang::get('Verify Email Address'))
|
|
|
66 |
->line(Lang::get('Please click the button below to verify your email address.'))
|
|
|
67 |
->action(Lang::get('Verify Email Address'), $url)
|
|
|
68 |
->line(Lang::get('If you did not create an account, no further action is required.'));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Get the verification URL for the given notifiable.
|
|
|
73 |
*
|
|
|
74 |
* @param mixed $notifiable
|
|
|
75 |
* @return string
|
|
|
76 |
*/
|
|
|
77 |
protected function verificationUrl($notifiable)
|
|
|
78 |
{
|
|
|
79 |
if (static::$createUrlCallback) {
|
|
|
80 |
return call_user_func(static::$createUrlCallback, $notifiable);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
return URL::temporarySignedRoute(
|
|
|
84 |
'verification.verify',
|
|
|
85 |
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
|
|
|
86 |
[
|
|
|
87 |
'id' => $notifiable->getKey(),
|
|
|
88 |
'hash' => sha1($notifiable->getEmailForVerification()),
|
|
|
89 |
]
|
|
|
90 |
);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Set a callback that should be used when creating the email verification URL.
|
|
|
95 |
*
|
|
|
96 |
* @param \Closure $callback
|
|
|
97 |
* @return void
|
|
|
98 |
*/
|
|
|
99 |
public static function createUrlUsing($callback)
|
|
|
100 |
{
|
|
|
101 |
static::$createUrlCallback = $callback;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Set a callback that should be used when building the notification mail message.
|
|
|
106 |
*
|
|
|
107 |
* @param \Closure $callback
|
|
|
108 |
* @return void
|
|
|
109 |
*/
|
|
|
110 |
public static function toMailUsing($callback)
|
|
|
111 |
{
|
|
|
112 |
static::$toMailCallback = $callback;
|
|
|
113 |
}
|
|
|
114 |
}
|