1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devpri\Tinre\Notifications; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use Illuminate\Support\Facades\Lang; |
8
|
|
|
|
9
|
|
|
class ResetPasswordNotification 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|null |
22
|
|
|
*/ |
23
|
|
|
public static $createUrlCallback; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The callback that should be used to build the mail message. |
27
|
|
|
* |
28
|
|
|
* @var \Closure|null |
29
|
|
|
*/ |
30
|
|
|
public static $toMailCallback; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a notification instance. |
34
|
|
|
* |
35
|
|
|
* @param string $token |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct($token) |
39
|
|
|
{ |
40
|
1 |
|
$this->token = $token; |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the notification's channels. |
45
|
|
|
* |
46
|
|
|
* @param mixed $notifiable |
47
|
|
|
* @return array|string |
48
|
|
|
*/ |
49
|
1 |
|
public function via($notifiable) |
50
|
|
|
{ |
51
|
1 |
|
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
|
|
|
if (static::$createUrlCallback) { |
67
|
|
|
$url = call_user_func(static::$createUrlCallback, $notifiable, $this->token); |
68
|
|
|
} else { |
69
|
|
|
$url = url(route('password.reset', [ |
70
|
|
|
'token' => $this->token, |
71
|
|
|
'email' => $notifiable->getEmailForPasswordReset(), |
72
|
|
|
], false)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return (new MailMessage) |
76
|
|
|
->subject(Lang::get('Reset Password Notification')) |
77
|
|
|
->line(Lang::get('You are receiving this email because we received a password reset request for your account.')) |
78
|
|
|
->action(Lang::get('Reset Password'), $url) |
79
|
|
|
->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')])) |
80
|
|
|
->line(Lang::get('If you did not request a password reset, no further action is required.')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set a callback that should be used when creating the reset password button URL. |
85
|
|
|
* |
86
|
|
|
* @param \Closure $callback |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public static function createUrlUsing($callback) |
90
|
|
|
{ |
91
|
|
|
static::$createUrlCallback = $callback; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set a callback that should be used when building the notification mail message. |
96
|
|
|
* |
97
|
|
|
* @param \Closure $callback |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public static function toMailUsing($callback) |
101
|
|
|
{ |
102
|
|
|
static::$toMailCallback = $callback; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|