| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 100.00% | 1 / 1 |  | 100.00% | 4 / 4 | CRAP |  | 100.00% | 27 / 27 | 
| ResetPassword |  | 100.00% | 1 / 1 |  | 100.00% | 4 / 4 | 8 |  | 100.00% | 27 / 27 | 
| __construct |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 4 / 4 | |||
| via |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 1 / 1 | |||
| toMail |  | 100.00% | 1 / 1 | 5 |  | 100.00% | 20 / 20 | |||
| toMailUsing |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 2 / 2 | |||
| 1 | <?php | 
| 2 | |
| 3 | namespace Qmp\Laravel\ExternalUsers\Notifications; | 
| 4 | |
| 5 | use Illuminate\Notifications\Messages\MailMessage; | 
| 6 | use Illuminate\Notifications\Notification; | 
| 7 | use Illuminate\Support\Facades\Lang; | 
| 8 | use Illuminate\Support\Str; | 
| 9 | |
| 10 | class ResetPassword extends Notification | 
| 11 | { | 
| 12 | /** | 
| 13 | * The password reset token. | 
| 14 | * | 
| 15 | * @var string | 
| 16 | */ | 
| 17 | public $token; | 
| 18 | |
| 19 | public $email; | 
| 20 | |
| 21 | public $config; | 
| 22 | |
| 23 | /** | 
| 24 | * The callback that should be used to build the mail message. | 
| 25 | * | 
| 26 | * @var \Closure|null | 
| 27 | */ | 
| 28 | public static $toMailCallback; | 
| 29 | |
| 30 | /** | 
| 31 | * Create a notification instance. | 
| 32 | * | 
| 33 | * @param string $token | 
| 34 | * @return void | 
| 35 | */ | 
| 36 | public function __construct($token, $email, $config = []) | 
| 37 | { | 
| 38 | $this->token = $token; | 
| 39 | $this->email = $email; | 
| 40 | $this->config = $config; | 
| 41 | } | 
| 42 | |
| 43 | /** | 
| 44 | * Get the notification's channels. | 
| 45 | * | 
| 46 | * @param mixed $notifiable | 
| 47 | * @return array|string | 
| 48 | */ | 
| 49 | public function via($notifiable) | 
| 50 | { | 
| 51 | return ['mail']; | 
| 52 | } | 
| 53 | |
| 54 | /** | 
| 55 | * Build the mail representation of the notification. | 
| 56 | * | 
| 57 | * @param mixed $notifiable | 
| 58 | * @return \Illuminate\Notifications\Messages\MailMessage | 
| 59 | */ | 
| 60 | public function toMail($notifiable) | 
| 61 | { | 
| 62 | if (static::$toMailCallback) { | 
| 63 | return call_user_func(static::$toMailCallback, $notifiable, $this->token); | 
| 64 | } | 
| 65 | |
| 66 | $url = isset($this->config['url']) ? 'http://' . $this->config['url'] : env('APP_EXTERNAL_FRONT_URL', 'https://dev-front-external-digital.advertise-me.net'); | 
| 67 | $logo = isset($this->config['logo']) ? (Str::startsWith($this->config['logo'], '/') ? $url : '') . $this->config['logo'] : $url . '/images/logo_adv.png'; | 
| 68 | $name = 'Qwamplify'; | 
| 69 | $colors = $this->config['colors'] ?? [ | 
| 70 | ['key' => 1, 'value' => '#242424'], | 
| 71 | ['key' => 2, 'value' => '#a8a8a8'], | 
| 72 | ['key' => 3, 'value' => '#3b3b3b'], | 
| 73 | ['key' => 4, 'value' => '#344aea'], | 
| 74 | ]; | 
| 75 | |
| 76 | $colors = collect($colors)->mapWithKeys(function($color) { | 
| 77 | return [$color['key'] => $color['value']]; | 
| 78 | }); | 
| 79 | |
| 80 | $respondUrl = $url . '/renew-pwd/' . $this->email . '/' . $this->token; | 
| 81 | |
| 82 | return (new MailMessage) | 
| 83 | ->view('emails_external::new_password', [ | 
| 84 | 'url' => $url, | 
| 85 | 'respondUrl' => $respondUrl, | 
| 86 | 'count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire'), | 
| 87 | 'logo' => $logo, | 
| 88 | 'name' => $name, | 
| 89 | 'colors' => $colors | 
| 90 | ]) | 
| 91 | ->subject(Lang::get('Reset Password Notification')); | 
| 92 | } | 
| 93 | |
| 94 | /** | 
| 95 | * Set a callback that should be used when building the notification mail message. | 
| 96 | * | 
| 97 | * @param \Closure $callback | 
| 98 | * @return void | 
| 99 | */ | 
| 100 | public static function toMailUsing($callback) | 
| 101 | { | 
| 102 | static::$toMailCallback = $callback; | 
| 103 | } | 
| 104 | } |