Notify admin of new user registration
This commit is contained in:
parent
d943d9bbff
commit
778780f3f2
@ -2,24 +2,27 @@
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\UserStateChanged;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use App\Models\Enums\PilotState;
|
||||
use \App\Events\UserRegistered;
|
||||
|
||||
/**
|
||||
* Handle sending emails on different events
|
||||
* @package App\Listeners
|
||||
*/
|
||||
class EmailEventListener
|
||||
class NotificationEventListener
|
||||
{
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen(
|
||||
UserRegistered::class,
|
||||
'App\Listeners\EmailEventListener@onUserRegister'
|
||||
\App\Events\UserRegistered::class,
|
||||
'App\Listeners\NotificationEventListener@onUserRegister'
|
||||
);
|
||||
|
||||
$events->listen(
|
||||
\App\Events\UserStateChanged::class,
|
||||
'App\Listeners\NotificationEventListener@onUserStateChange'
|
||||
);
|
||||
}
|
||||
|
||||
@ -34,6 +37,14 @@ class EmailEventListener
|
||||
. PilotState::label($event->user->state)
|
||||
. ', sending active email');
|
||||
|
||||
# First send the admin a notification
|
||||
$admin_email = setting('general.admin_email');
|
||||
if (!empty($admin_email)) {
|
||||
$email = new \App\Mail\Admin\UserRegistered($event->user);
|
||||
Mail::to($admin_email)->send($email);
|
||||
}
|
||||
|
||||
# Then notify the user
|
||||
if($event->user->state === PilotState::ACTIVE) {
|
||||
$email = new \App\Mail\UserRegistered(
|
||||
$event->user,
|
29
app/Mail/Admin/UserRegistered.php
Normal file
29
app/Mail/Admin/UserRegistered.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\Admin;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserRegistered extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $subject, $user;
|
||||
|
||||
public function __construct(User $user, $subject=null)
|
||||
{
|
||||
$this->subject = $subject ?: 'A new user registered';
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->markdown('emails.admin.registered')
|
||||
->subject($this->subject)
|
||||
->with(['user' => $this->user]);
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
];
|
||||
|
||||
protected $subscribe = [
|
||||
'App\Listeners\EmailEventListener',
|
||||
'App\Listeners\NotificationEventListener',
|
||||
];
|
||||
|
||||
/**
|
||||
|
9
resources/views/emails/admin/registered.blade.php
Normal file
9
resources/views/emails/admin/registered.blade.php
Normal file
@ -0,0 +1,9 @@
|
||||
@component('mail::message')
|
||||
A new user has signed up!
|
||||
|
||||
Name: {!! $user->name !!}!
|
||||
Email: {!! $user->email !!}
|
||||
State: {!! PilotState::label($user->state) !!}
|
||||
|
||||
{{ config('app.name') }}
|
||||
@endcomponent
|
Loading…
Reference in New Issue
Block a user