| 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\Facades\Lang;
|
|
|
8 |
|
|
|
9 |
class ResetPassword extends Notification
|
|
|
10 |
{
|
|
|
11 |
/**
|
|
|
12 |
* The password reset token.
|
|
|
13 |
*
|
|
|
14 |
* @var string
|
|
|
15 |
*/
|
|
|
16 |
public $token;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* The callback that should be used to create the reset password URL.
|
|
|
20 |
*
|
|
|
21 |
* @var (\Closure(mixed, string): string)|null
|
|
|
22 |
*/
|
|
|
23 |
public static $createUrlCallback;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* The callback that should be used to build the mail message.
|
|
|
27 |
*
|
|
|
28 |
* @var (\Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage)|null
|
|
|
29 |
*/
|
|
|
30 |
public static $toMailCallback;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Create a notification instance.
|
|
|
34 |
*
|
|
|
35 |
* @param string $token
|
|
|
36 |
* @return void
|
|
|
37 |
*/
|
|
|
38 |
public function __construct($token)
|
|
|
39 |
{
|
|
|
40 |
$this->token = $token;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Get the notification's channels.
|
|
|
45 |
*
|
|
|
46 |
* @param mixed $notifiable
|
|
|
47 |
* @return array|string
|
|
|
48 |
*/
|
|
|
49 |
public function via($notifiable)
|
|
|
50 |
{
|
|
|
51 |
return ['mail'];
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Build the mail representation of the notification.
|
|
|
56 |
*
|
|
|
57 |
* @param mixed $notifiable
|
|
|
58 |
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
59 |
*/
|
|
|
60 |
public function toMail($notifiable)
|
|
|
61 |
{
|
|
|
62 |
if (static::$toMailCallback) {
|
|
|
63 |
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
return $this->buildMailMessage($this->resetUrl($notifiable));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Get the reset password notification mail message for the given URL.
|
|
|
71 |
*
|
|
|
72 |
* @param string $url
|
|
|
73 |
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
74 |
*/
|
|
|
75 |
protected function buildMailMessage($url)
|
|
|
76 |
{
|
|
|
77 |
return (new MailMessage)
|
|
|
78 |
->subject(Lang::get('Reset Password Notification'))
|
|
|
79 |
->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
|
|
|
80 |
->action(Lang::get('Reset Password'), $url)
|
|
|
81 |
->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
|
|
|
82 |
->line(Lang::get('If you did not request a password reset, no further action is required.'));
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Get the reset URL for the given notifiable.
|
|
|
87 |
*
|
|
|
88 |
* @param mixed $notifiable
|
|
|
89 |
* @return string
|
|
|
90 |
*/
|
|
|
91 |
protected function resetUrl($notifiable)
|
|
|
92 |
{
|
|
|
93 |
if (static::$createUrlCallback) {
|
|
|
94 |
return call_user_func(static::$createUrlCallback, $notifiable, $this->token);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
return url(route('password.reset', [
|
|
|
98 |
'token' => $this->token,
|
|
|
99 |
'email' => $notifiable->getEmailForPasswordReset(),
|
|
|
100 |
], false));
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Set a callback that should be used when creating the reset password button URL.
|
|
|
105 |
*
|
|
|
106 |
* @param \Closure(mixed, string): string $callback
|
|
|
107 |
* @return void
|
|
|
108 |
*/
|
|
|
109 |
public static function createUrlUsing($callback)
|
|
|
110 |
{
|
|
|
111 |
static::$createUrlCallback = $callback;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Set a callback that should be used when building the notification mail message.
|
|
|
116 |
*
|
|
|
117 |
* @param \Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage $callback
|
|
|
118 |
* @return void
|
|
|
119 |
*/
|
|
|
120 |
public static function toMailUsing($callback)
|
|
|
121 |
{
|
|
|
122 |
static::$toMailCallback = $callback;
|
|
|
123 |
}
|
|
|
124 |
}
|