Commit 6ee967f6 authored by Nicolas Widart's avatar Nicolas Widart

Using new Mailable class for the reset password email

parent ffa8b6de
<?php
namespace Modules\User\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Modules\User\Entities\UserInterface;
class ResetPasswordEmail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* @var UserInterface
*/
public $user;
/**
* @var
*/
public $code;
protected $subject = 'Reset your account password.';
public function __construct(UserInterface $user, $code)
{
$this->user = $user;
$this->code = $code;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('user::emails.reminder');
}
}
...@@ -2,19 +2,26 @@ ...@@ -2,19 +2,26 @@
namespace Modules\User\Events\Handlers; namespace Modules\User\Events\Handlers;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message; use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Modules\User\Emails\ResetPasswordEmail;
use Modules\User\Events\UserHasBegunResetProcess; use Modules\User\Events\UserHasBegunResetProcess;
class SendResetCodeEmail class SendResetCodeEmail
{ {
public function handle(UserHasBegunResetProcess $event) /**
* @var Mailer
*/
private $mailer;
public function __construct(Mailer $mailer)
{ {
$user = $event->user; $this->mailer = $mailer;
$code = $event->code; }
Mail::queue('user::emails.reminder', compact('user', 'code'), function (Message $m) use ($user) { public function handle(UserHasBegunResetProcess $event)
$m->to($user->email)->subject('Reset your account password.'); {
}); $this->mailer->to($event->user->email)->send(new ResetPasswordEmail($event->user, $event->code));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment