|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Auth\Notifications; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Bus\Queueable; |
|
8
|
|
|
use Illuminate\Notifications\Notification; |
|
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
10
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
|
11
|
|
|
|
|
12
|
|
|
class ManagerPasswordResetNotification extends Notification implements ShouldQueue |
|
13
|
|
|
{ |
|
14
|
|
|
use Queueable; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The callback that should be used to build the mail message. |
|
18
|
|
|
* |
|
19
|
|
|
* @var \Closure|null |
|
20
|
|
|
*/ |
|
21
|
|
|
public static $toMailCallback; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The password reset token. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $token; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The password reset expiration date. |
|
32
|
|
|
* |
|
33
|
|
|
* @var int |
|
34
|
|
|
*/ |
|
35
|
|
|
public $expiration; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Create a notification instance. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $token |
|
41
|
|
|
* @param int $expiration |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(string $token, int $expiration) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->token = $token; |
|
46
|
|
|
$this->expiration = $expiration; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the notification's channels. |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $notifiable |
|
53
|
|
|
* |
|
54
|
|
|
* @return array|string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function via($notifiable) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
return ['mail']; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Build the mail representation of the notification. |
|
63
|
|
|
* |
|
64
|
|
|
* @param mixed $notifiable |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
|
67
|
|
|
*/ |
|
68
|
|
|
public function toMail($notifiable): MailMessage |
|
69
|
|
|
{ |
|
70
|
|
|
if (static::$toMailCallback) { |
|
71
|
|
|
return call_user_func(static::$toMailCallback, $notifiable); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$email = $notifiable->getEmailForPasswordReset(); |
|
75
|
|
|
$link = route('managerarea.passwordreset.reset')."?email={$email}&expiration={$this->expiration}&token={$this->token}"; |
|
76
|
|
|
|
|
77
|
|
|
return (new MailMessage()) |
|
78
|
|
|
->subject(trans('cortex/auth::emails.passwordreset.request.subject')) |
|
79
|
|
|
->line(trans('cortex/auth::emails.passwordreset.request.intro', ['expire' => now()->createFromTimestamp($this->expiration)->diffForHumans()])) |
|
80
|
|
|
->action(trans('cortex/auth::emails.passwordreset.request.action'), $link) |
|
81
|
|
|
->line(trans('cortex/auth::emails.passwordreset.request.outro', ['created_at' => now(), 'ip' => request()->ip(), 'agent' => request()->userAgent()])); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Set a callback that should be used when building the notification mail message. |
|
86
|
|
|
* |
|
87
|
|
|
* @param \Closure $callback |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function toMailUsing($callback) |
|
92
|
|
|
{ |
|
93
|
|
|
static::$toMailCallback = $callback; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.