feat: add account deletion notifications
This also sets up notifications for all site admins
This commit is contained in:
parent
a265debe4c
commit
b8242dbc87
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Notifications\AccountDeleted;
|
||||
use App\Notifications\UserDeletedAccount;
|
||||
use App\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
@ -10,6 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class ProcessAccountDelete implements ShouldQueue
|
||||
{
|
||||
@ -40,12 +43,20 @@ class ProcessAccountDelete implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// It shouldn't need the suspension service, because if it was dispatched, the account was already locked
|
||||
|
||||
Log::alert('[Worker] Processing account deletion request', [
|
||||
'email' => $this->user->email
|
||||
]);
|
||||
|
||||
$this->user->delete();
|
||||
$email = $this->user->email;
|
||||
$name = $this->user->name;
|
||||
|
||||
if ($this->user->delete()) {
|
||||
Notification::route('mail', [
|
||||
$email => $name
|
||||
])->notify(new AccountDeleted($name));
|
||||
|
||||
// Notify admins
|
||||
Notification::send(User::role('admin')->get(), new UserDeletedAccount($email));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class UserAccountDeleteConfirmation extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->subject('[ACTION REQUIRED] Please confirm account removal')
|
||||
return $this->subject(config('app.name') . ' - please confirm account removal (action required)')
|
||||
->view('mail.deleted-account');
|
||||
}
|
||||
}
|
||||
|
69
app/Notifications/AccountDeleted.php
Normal file
69
app/Notifications/AccountDeleted.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class AccountDeleted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public string $name;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
// Adjust to notify external user
|
||||
return (new MailMessage)
|
||||
->greeting('Hi ' . $this->name . ',')
|
||||
->from(config('notification.sender.address'), config('notification.sender.name'))
|
||||
->subject(config('app.name').' - account deleted permanently')
|
||||
->line('Thank you for confirming your account deletion request. We\'re sorry to see you go!')
|
||||
->line('Unless you sign up again, this is the last email you\'ll be receiving from us.')
|
||||
->line('Please let us know if there\'s any feedback you\'d like to share. You can use the feedback widget located on the left-hand side of our website, or the chat widget located on the lower right corner.')
|
||||
->line('See you around!')
|
||||
->salutation('The team at ' . config('app.name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
70
app/Notifications/UserDeletedAccount.php
Normal file
70
app/Notifications/UserDeletedAccount.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class UserDeletedAccount extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* @var string The email belonging to the user who wiped their acct.
|
||||
*/
|
||||
public string $deletedEmail;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($deletedEmail)
|
||||
{
|
||||
$this->deletedEmail = $deletedEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage)
|
||||
->greeting('Hi ' . $notifiable->name . ',')
|
||||
->from(config('notification.sender.address'), config('notification.sender.name'))
|
||||
->subject(config('app.name').' - someone deleted their account')
|
||||
->line("The user {$this->deletedEmail} has just deleted their account. You may wish to review the situation.")
|
||||
->line('You are receiving this email because you\'re a site admin.')
|
||||
->action('View current users', url(route('registeredPlayerList')))
|
||||
->salutation('The team at ' . config('app.name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ class UserObserver
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
Log::debug('User observer has been initialised and ready for use!');
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user