From a265debe4c5cf040d5a9511b846e1e83013af75b Mon Sep 17 00:00:00 2001 From: miguel456 Date: Mon, 7 Mar 2022 19:43:14 +0000 Subject: [PATCH] feat: add account unlock/lock notifications --- app/Notifications/AccountLocked.php | 61 +++++++++++++++++ app/Notifications/AccountUnlocked.php | 66 +++++++++++++++++++ app/Services/AccountSuspensionService.php | 6 ++ resources/views/mail/account-locked.blade.php | 18 +++++ 4 files changed, 151 insertions(+) create mode 100644 app/Notifications/AccountLocked.php create mode 100644 app/Notifications/AccountUnlocked.php create mode 100644 resources/views/mail/account-locked.blade.php diff --git a/app/Notifications/AccountLocked.php b/app/Notifications/AccountLocked.php new file mode 100644 index 0000000..ccec411 --- /dev/null +++ b/app/Notifications/AccountLocked.php @@ -0,0 +1,61 @@ +from(config('notification.sender.address'), config('notification.sender.name')) + ->subject(config('app.name').' - account locked') + ->markdown('mail.account-locked', ['name' => $notifiable->name]); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/app/Notifications/AccountUnlocked.php b/app/Notifications/AccountUnlocked.php new file mode 100644 index 0000000..fd5dfb9 --- /dev/null +++ b/app/Notifications/AccountUnlocked.php @@ -0,0 +1,66 @@ +greeting('Hi ' . $notifiable->name . ',') + ->from(config('notification.sender.address'), config('notification.sender.name')) + ->subject(config('app.name').' - account unlocked') + ->line('We wanted to let you know that your account at ' . config('app.name') . ' is now unlocked. This means the circumstances surrounding your account\'s standing are now resolved.') + ->line('You can sign in and use the app normally again.') + ->line('If there\'s anything we can help you with, don\'t hesitate to reach out.') + ->action('Sign in', url(route('login'))) + ->salutation('The team at ' . config('app.name')); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/app/Services/AccountSuspensionService.php b/app/Services/AccountSuspensionService.php index 9e9137d..ca3088b 100755 --- a/app/Services/AccountSuspensionService.php +++ b/app/Services/AccountSuspensionService.php @@ -4,6 +4,8 @@ namespace App\Services; use App\Ban; +use App\Notifications\AccountLocked; +use App\Notifications\AccountUnlocked; use App\User; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; @@ -81,6 +83,8 @@ class AccountSuspensionService ]); $user->administratively_locked = 1; + $user->notify(new AccountLocked); + return $user->save(); } @@ -98,6 +102,8 @@ class AccountSuspensionService ]); $user->administratively_locked = 0; + $user->notify(new AccountUnlocked); + return $user->save(); } diff --git a/resources/views/mail/account-locked.blade.php b/resources/views/mail/account-locked.blade.php new file mode 100644 index 0000000..54a6f00 --- /dev/null +++ b/resources/views/mail/account-locked.blade.php @@ -0,0 +1,18 @@ +@component('mail::message') +# Hi {{ $name }}, + +We wanted to let you know that your account at {{ config('app.name') }} has been locked due to security concerns. Don't worry! You haven't been suspended! We lock accounts for a number of reasons, including, but not limited to: + + - Suspicious activity was detected; + - You failed to activate 2FA within the required timeframe; + - Your password was detected on a 3rd party security breach; + - You started an account deletion request; + - Your password expired. + +Please note that your account may be locked for reasons other than those listed above; If you think this was an error, please let us know, but keep in mind that this is an automated process and we can't manually unlock accounts. You will not be able to sign in or use the app while your account is locked. + +Usually, you will receive another email with more information regarding your specific circumstances. + +Thank you,
+The team at {{ config('app.name') }} +@endcomponent