Fixes for password reset via queues

This commit is contained in:
Deon George 2020-01-30 21:39:25 +11:00
parent 0eb0d4739e
commit b85aabe979
6 changed files with 38 additions and 86 deletions

View File

@ -19,7 +19,7 @@ BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
QUEUE_CONNECTION=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null

View File

@ -0,0 +1,33 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPassword extends ResetPasswordNotification implements ShouldQueue
{
use Queueable;
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return (new MailMessage)
->markdown('email.user.passwordreset',[
'site'=>$notifiable->site,
'user'=>$notifiable,
'reset_link'=>route('password.reset',$this->token,true),
]);
}
}

View File

@ -1,80 +0,0 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPasswordNotification extends Notification
{
use Queueable;
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* The callback that should be used to build the mail message.
*
* @var \Closure|null
*/
public static $toMailCallback;
/**
* Create a notification instance.
*
* @param string $token
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return (new MailMessage)
->markdown('email.user.passwordreset',[
'site'=>config('SITE_SETUP'),
'user'=>$notifiable,
'reset_link'=>route('password.reset',$this->token,true),
]);
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}

View File

@ -11,7 +11,7 @@ use Laravel\Passport\HasApiTokens;
use Leenooks\Carbon;
use Leenooks\Traits\UserSwitch;
use App\Notifications\ResetPasswordNotification;
use App\Notifications\ResetPassword as ResetPasswordNotification;
use App\Models\Service;
use Spinen\QuickBooks\HasQuickBooksToken;
@ -200,7 +200,7 @@ class User extends Authenticatable
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
}
/** Scopes **/

View File

@ -132,6 +132,6 @@ return [
*/
'log_channel' => env('MAIL_LOG_CHANNEL'),
'local_domain' => env('MAIL_HOST'),
'local_domain' => env('HOSTNAME'),
];

View File

@ -14,8 +14,7 @@
"laravel-mix": "^5.0.1",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"vue-template-compiler": "^2.6.11"
"sass-loader": "^8.0.0"
},
"dependencies": {
"axios": "^0.19",