From 7b42b1f3198c694d2e2d7a21229d03e15a314355 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sun, 12 Dec 2021 10:57:28 +0330 Subject: [PATCH] send PasswordRest notification on successfull reset --- .../Actions/ResetPasswordAction.php | 21 ++++++++++----- .../Notifications/PasswordReset.php | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/Containers/AppSection/Authentication/Notifications/PasswordReset.php diff --git a/app/Containers/AppSection/Authentication/Actions/ResetPasswordAction.php b/app/Containers/AppSection/Authentication/Actions/ResetPasswordAction.php index b65e7900c..e026b64a7 100644 --- a/app/Containers/AppSection/Authentication/Actions/ResetPasswordAction.php +++ b/app/Containers/AppSection/Authentication/Actions/ResetPasswordAction.php @@ -3,7 +3,9 @@ namespace App\Containers\AppSection\Authentication\Actions; use App\Containers\AppSection\Authentication\Exceptions\InvalidResetPasswordTokenException; +use App\Containers\AppSection\Authentication\Notifications\PasswordReset; use App\Containers\AppSection\Authentication\UI\API\Requests\ResetPasswordRequest; +use App\Containers\AppSection\User\Tasks\FindUserByEmailTask; use App\Ship\Exceptions\NotFoundException; use App\Ship\Exceptions\UpdateResourceFailedException; use App\Ship\Parents\Actions\Action; @@ -38,11 +40,18 @@ function ($user, $password) { } ); - return match ($status) { - Password::INVALID_TOKEN => throw new InvalidResetPasswordTokenException(), - Password::INVALID_USER => throw new NotFoundException('User Not Found.'), - Password::PASSWORD_RESET => $status, - default => throw new UpdateResourceFailedException() - }; + switch ($status) { + case Password::INVALID_TOKEN: + throw new InvalidResetPasswordTokenException(); + case Password::INVALID_USER: + throw new NotFoundException('User Not Found.'); + case Password::PASSWORD_RESET: + $user = app(FindUserByEmailTask::class)->run($sanitizedData['email']); + $user->notify(new PasswordReset()); + + return $status; + default: + throw new UpdateResourceFailedException(); + } } } diff --git a/app/Containers/AppSection/Authentication/Notifications/PasswordReset.php b/app/Containers/AppSection/Authentication/Notifications/PasswordReset.php new file mode 100644 index 000000000..582a45b84 --- /dev/null +++ b/app/Containers/AppSection/Authentication/Notifications/PasswordReset.php @@ -0,0 +1,26 @@ +subject('Password Reset') + ->line('Your password has been reset successfully.'); + } +}