63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:前台用户邮箱找回密码通知
|
||
*
|
||
* 自定义找回密码邮件标题与正文文案,统一跳转到前台独立重置页。
|
||
*/
|
||
|
||
namespace App\Notifications;
|
||
|
||
use Illuminate\Notifications\Messages\MailMessage;
|
||
use Illuminate\Notifications\Notification;
|
||
|
||
/**
|
||
* 类功能:向用户发送邮箱重置密码邮件。
|
||
*/
|
||
class ResetUserPasswordNotification extends Notification
|
||
{
|
||
/**
|
||
* 创建通知实例时保存本次重置令牌。
|
||
*/
|
||
public function __construct(
|
||
#[\SensitiveParameter]
|
||
public string $token
|
||
) {}
|
||
|
||
/**
|
||
* 指定该通知只通过邮件渠道发送。
|
||
*
|
||
* @return array<int, string>
|
||
*/
|
||
public function via(mixed $notifiable): array
|
||
{
|
||
return ['mail'];
|
||
}
|
||
|
||
/**
|
||
* 构建找回密码邮件内容。
|
||
*/
|
||
public function toMail(mixed $notifiable): MailMessage
|
||
{
|
||
return (new MailMessage)
|
||
->subject('和平聊吧 - 邮箱找回密码')
|
||
->greeting('您好,'.$notifiable->username.':')
|
||
->line('系统收到了这次密码找回申请,请点击下方按钮重新设置登录密码。')
|
||
->line('该链接仅适用于当前绑定邮箱的账号,请勿转发给他人。')
|
||
->action('立即重置密码', $this->buildResetUrl($notifiable))
|
||
->line('重置链接将在 '.config('auth.passwords.'.config('auth.defaults.passwords').'.expire').' 分钟后失效。')
|
||
->line('如果这不是您本人发起的操作,直接忽略本邮件即可。');
|
||
}
|
||
|
||
/**
|
||
* 生成前台独立重置密码页面地址。
|
||
*/
|
||
private function buildResetUrl(mixed $notifiable): string
|
||
{
|
||
return url(route('password.reset', [
|
||
'token' => $this->token,
|
||
'email' => $notifiable->getEmailForPasswordReset(),
|
||
], false));
|
||
}
|
||
}
|