|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Binaryk\LaravelRestify\Notifications; |
| 4 | + |
| 5 | +use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailLaravel; |
| 6 | +use Illuminate\Notifications\Messages\MailMessage; |
| 7 | +use Illuminate\Notifications\Notification; |
| 8 | +use Illuminate\Support\Carbon; |
| 9 | +use Illuminate\Support\Facades\Config; |
| 10 | +use Illuminate\Support\Facades\Lang; |
| 11 | +use Illuminate\Support\Facades\URL; |
| 12 | + |
| 13 | +class VerifyEmail extends VerifyEmailLaravel |
| 14 | +{ |
| 15 | + public function toMail($notifiable) |
| 16 | + { |
| 17 | + $verificationUrl = $this->verificationUrl($notifiable); |
| 18 | + |
| 19 | + if (static::$toMailCallback) { |
| 20 | + return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl); |
| 21 | + } |
| 22 | + |
| 23 | + return (new MailMessage) |
| 24 | + ->subject(Lang::get('Verify Email Address')) |
| 25 | + ->line(Lang::get('Please click the button below to verify your email address.')) |
| 26 | + ->action(Lang::get('Verify Email Address'), $verificationUrl) |
| 27 | + ->line(Lang::get('If you did not create an account, no further action is required.')); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Get the verification URL for the given notifiable. |
| 32 | + * |
| 33 | + * @param mixed $notifiable |
| 34 | + * @return string |
| 35 | + */ |
| 36 | + protected function verificationUrl($notifiable) |
| 37 | + { |
| 38 | + return URL::temporarySignedRoute( |
| 39 | + 'restify.verification.verify', |
| 40 | + Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), |
| 41 | + [ |
| 42 | + 'id' => $notifiable->getKey(), |
| 43 | + 'hash' => sha1($notifiable->getEmailForVerification()), |
| 44 | + ] |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Set a callback that should be used when building the notification mail message. |
| 50 | + * |
| 51 | + * @param \Closure $callback |
| 52 | + * @return void |
| 53 | + */ |
| 54 | + public static function toMailUsing($callback) |
| 55 | + { |
| 56 | + static::$toMailCallback = $callback; |
| 57 | + } |
| 58 | +} |
0 commit comments