ResetPassword.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Notifications\Email;
  3. use Illuminate\Notifications\Messages\MailMessage;
  4. use Illuminate\Notifications\Notification;
  5. use Illuminate\Support\Facades\Lang;
  6. class ResetPassword extends Notification
  7. {
  8. /**
  9. * The password reset token.
  10. *
  11. * @var string
  12. */
  13. public $token;
  14. /**
  15. * The callback that should be used to create the reset password URL.
  16. *
  17. * @var \Closure|null
  18. */
  19. public static $createUrlCallback;
  20. /**
  21. * The callback that should be used to build the mail message.
  22. *
  23. * @var \Closure|null
  24. */
  25. public static $toMailCallback;
  26. /**
  27. * Create a notification instance.
  28. *
  29. * @param string $token
  30. * @return void
  31. */
  32. public function __construct($token)
  33. {
  34. $this->token = $token;
  35. }
  36. /**
  37. * Get the notification's channels.
  38. *
  39. * @param mixed $notifiable
  40. * @return array|string
  41. */
  42. public function via($notifiable)
  43. {
  44. return ['mail'];
  45. }
  46. /**
  47. * Build the mail representation of the notification.
  48. *
  49. * @param mixed $notifiable
  50. * @return \Illuminate\Notifications\Messages\MailMessage
  51. */
  52. public function toMail($notifiable)
  53. {
  54. if (static::$toMailCallback) {
  55. return call_user_func(static::$toMailCallback, $notifiable, $this->token);
  56. }
  57. if (static::$createUrlCallback) {
  58. $url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
  59. } else {
  60. $url = url(route('password.reset', [
  61. 'token' => $this->token,
  62. 'email' => $notifiable->getEmailForPasswordReset(),
  63. ], false));
  64. }
  65. return (new MailMessage)
  66. ->theme((app()->getLocale() == 'fa') ? 'rtl-theme' : 'default')
  67. ->greeting(Lang::get('mail.resetPassword.greeting'))
  68. ->salutation(Lang::get('mail.resetPassword.salutation'))
  69. ->subject(Lang::get('mail.resetPassword.subject'))
  70. ->line(Lang::get('mail.resetPassword.excerpt'))
  71. ->action(Lang::get('mail.resetPassword.button'), $url)
  72. ->line(Lang::get('mail.resetPassword.timeout', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]));
  73. }
  74. /**
  75. * Set a callback that should be used when creating the reset password button URL.
  76. *
  77. * @param \Closure $callback
  78. * @return void
  79. */
  80. public static function createUrlUsing($callback)
  81. {
  82. static::$createUrlCallback = $callback;
  83. }
  84. /**
  85. * Set a callback that should be used when building the notification mail message.
  86. *
  87. * @param \Closure $callback
  88. * @return void
  89. */
  90. public static function toMailUsing($callback)
  91. {
  92. static::$toMailCallback = $callback;
  93. }
  94. }