2017-12-23 02:00:57 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use Log;
|
2017-12-23 02:46:46 +08:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2017-12-23 02:00:57 +08:00
|
|
|
|
2017-12-23 02:46:46 +08:00
|
|
|
use App\Models\Enums\PilotState;
|
|
|
|
use \App\Events\UserRegistered;
|
2017-12-23 02:00:57 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle sending emails on different events
|
|
|
|
* @package App\Listeners
|
|
|
|
*/
|
|
|
|
class EmailEventListener
|
|
|
|
{
|
|
|
|
public function subscribe($events)
|
|
|
|
{
|
|
|
|
$events->listen(
|
|
|
|
UserRegistered::class,
|
|
|
|
'App\Listeners\EmailEventListener@onUserRegister'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-23 02:46:46 +08:00
|
|
|
/**
|
|
|
|
* Send an email when the user registered
|
|
|
|
* @param UserRegistered $event
|
|
|
|
*/
|
2017-12-23 02:00:57 +08:00
|
|
|
public function onUserRegister(UserRegistered $event)
|
|
|
|
{
|
2017-12-23 02:46:46 +08:00
|
|
|
Log::info('onUserRegister: '
|
|
|
|
. $event->user->pilot_id . ' is '
|
|
|
|
. PilotState::label($event->user->state)
|
|
|
|
. ', sending active email');
|
|
|
|
|
|
|
|
if($event->user->state === PilotState::ACTIVE) {
|
|
|
|
Mail::to($event->user->email)->send(new \App\Mail\UserRegistered($event->user));
|
|
|
|
} else if($event->user->state === PilotState::PENDING) {
|
|
|
|
Mail::to($event->user->email)->send(new \App\Mail\UserPending($event->user));
|
|
|
|
}
|
2017-12-23 02:00:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|