2
0

PasswordResetMail.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Mail\V3;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Mail\Mailable;
  5. use Illuminate\Mail\Mailables\Content;
  6. use Illuminate\Mail\Mailables\Envelope;
  7. use Illuminate\Queue\SerializesModels;
  8. /**
  9. * v3 的密码重置邮件。
  10. *
  11. * 与 v2 的 `App\Mail\ForgotPassword` 的区别:链接由调用方用服务端配置拼好传进来,
  12. * 不接受客户端提供的站点地址(v2 收 `dashboard` 参数原样拼进链接,攻击者可借此
  13. * 把 reset token 引到自己的域名)。邮件模板沿用 `emails.reset_password.*`。
  14. */
  15. class PasswordResetMail extends Mailable
  16. {
  17. use Queueable, SerializesModels;
  18. /**
  19. * @param string $url 完整的重置链接(含 token)
  20. * @param string $lang 模板语言,调用方保证是 `emails.reset_password.*` 里存在的那几个
  21. */
  22. public function __construct(
  23. public string $url,
  24. public string $lang,
  25. ) {}
  26. public function envelope(): Envelope
  27. {
  28. return new Envelope(
  29. subject: __('passwords.subject', [], $this->lang),
  30. );
  31. }
  32. public function content(): Content
  33. {
  34. return new Content(
  35. view: 'emails.reset_password.'.$this->lang,
  36. with: ['url' => $this->url],
  37. );
  38. }
  39. }