erdemkeren /
laravel-otp
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * @copyright 2018 Hilmi Erdem KEREN |
||
| 5 | * @license MIT |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace Erdemkeren\Otp; |
||
| 9 | |||
| 10 | use Illuminate\Bus\Queueable; |
||
| 11 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 12 | use Illuminate\Notifications\Messages\MailMessage; |
||
| 13 | use Illuminate\Notifications\Notification; |
||
| 14 | use Illuminate\Support\Traits\Macroable; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class TokenNotification. |
||
| 18 | */ |
||
| 19 | class TokenNotification extends Notification implements ShouldQueue |
||
| 20 | { |
||
| 21 | use Queueable, Macroable; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | |||
| 23 | /** |
||
| 24 | * The token implementation. |
||
| 25 | * |
||
| 26 | * @var TokenInterface |
||
| 27 | */ |
||
| 28 | public $token; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * TokenGenerated constructor. |
||
| 32 | * |
||
| 33 | * @param TokenInterface $token |
||
| 34 | */ |
||
| 35 | 6 | public function __construct(TokenInterface $token) |
|
| 36 | { |
||
| 37 | 6 | $this->token = $token; |
|
| 38 | 6 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Get the notification's delivery channels. |
||
| 42 | * |
||
| 43 | * @param mixed $notifiable |
||
| 44 | * |
||
| 45 | * @return array |
||
| 46 | */ |
||
| 47 | 2 | public function via($notifiable) |
|
| 48 | { |
||
| 49 | 2 | $channels = ! is_null($notifiable) && method_exists($notifiable, 'otpChannels') && ! empty($notifiable->otpChannels()) |
|
| 50 | 1 | ? $notifiable->otpChannels() |
|
| 51 | 2 | : config('otp.default_channels'); |
|
| 52 | |||
| 53 | 2 | return \is_array($channels) |
|
| 54 | 1 | ? $channels |
|
| 55 | 2 | : array_map('trim', explode(',', $channels)); |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Get the mail presentation of the notification. |
||
| 60 | * |
||
| 61 | * @return MailMessage |
||
| 62 | */ |
||
| 63 | 1 | public function toMail(): MailMessage |
|
| 64 | { |
||
| 65 | 1 | return (new MailMessage()) |
|
| 66 | 1 | ->subject(config('app.name').' One Time Password') |
|
| 67 | 1 | ->greeting('Hello!') |
|
| 68 | 1 | ->line('Somebody recently requested for a one-time password in behalf of you.') |
|
| 69 | 1 | ->line('You can enter the following reset code: '.$this->token->plainText()) |
|
| 70 | 1 | ->line('If you didn\'t request the password, simply ignore this message.'); |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the sms presentation of the notification. |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 1 | public function toSms(): string |
|
| 79 | { |
||
| 80 | return 'Somebody recently requested a one-time password.' |
||
| 81 | 1 | ." You can enter the following reset code: {$this->token->plainText()}" |
|
| 82 | 1 | .' If you didn\'t request the password, simply ignore this message.'; |
|
| 83 | } |
||
| 84 | } |
||
| 85 |