diff --git a/app/Containers/AppSection/User/Actions/UpdateUserPasswordAction.php b/app/Containers/AppSection/User/Actions/UpdateUserPasswordAction.php index e90e46358..fd640bcba 100644 --- a/app/Containers/AppSection/User/Actions/UpdateUserPasswordAction.php +++ b/app/Containers/AppSection/User/Actions/UpdateUserPasswordAction.php @@ -4,6 +4,7 @@ use Apiato\Core\Exceptions\IncorrectIdException; use App\Containers\AppSection\User\Models\User; +use App\Containers\AppSection\User\Notifications\PasswordUpdatedNotification; use App\Containers\AppSection\User\Tasks\UpdateUserTask; use App\Containers\AppSection\User\UI\API\Requests\UpdateUserPasswordRequest; use App\Ship\Exceptions\NotFoundException; @@ -22,10 +23,13 @@ class UpdateUserPasswordAction extends Action public function run(UpdateUserPasswordRequest $request): User { $sanitizedData = $request->sanitizeInput([ - 'current_password', 'new_password', ]); - return app(UpdateUserTask::class)->run(['password' => $sanitizedData['new_password']], $request->id); + $user = app(UpdateUserTask::class)->run(['password' => $sanitizedData['new_password']], $request->id); + + $user->notify(new PasswordUpdatedNotification()); + + return $user; } } diff --git a/app/Containers/AppSection/User/Notifications/PasswordUpdatedNotification.php b/app/Containers/AppSection/User/Notifications/PasswordUpdatedNotification.php new file mode 100644 index 000000000..8a4812e53 --- /dev/null +++ b/app/Containers/AppSection/User/Notifications/PasswordUpdatedNotification.php @@ -0,0 +1,28 @@ +subject('Account Change Notice') + ->line('We wanted to let you know that some information was changed for your account:') + ->line('Your password has been change.') + ->line('If you recently made account changes, please disregard this message. However, if you did NOT make any changes to your account, we recommend you change your password and make appropriate corrections as soon as possible to ensure account security.'); + } +} diff --git a/app/Containers/AppSection/User/UI/API/Tests/Functional/UpdateUserPasswordTest.php b/app/Containers/AppSection/User/UI/API/Tests/Functional/UpdateUserPasswordTest.php index a0eaf6cf6..1a5fc5f8f 100644 --- a/app/Containers/AppSection/User/UI/API/Tests/Functional/UpdateUserPasswordTest.php +++ b/app/Containers/AppSection/User/UI/API/Tests/Functional/UpdateUserPasswordTest.php @@ -2,7 +2,9 @@ namespace App\Containers\AppSection\User\UI\API\Tests\Functional; +use App\Containers\AppSection\User\Notifications\PasswordUpdatedNotification; use App\Containers\AppSection\User\UI\API\Tests\ApiTestCase; +use Illuminate\Support\Facades\Notification; use Illuminate\Testing\Fluent\AssertableJson; /** @@ -22,6 +24,8 @@ class UpdateUserPasswordTest extends ApiTestCase public function testGivenUserAlreadyHaveAPassword_UpdateUserPassword(): void { + Notification::fake(); + $user = $this->getTestingUser([ 'password' => 'Av@dakedavra!', ]); @@ -40,6 +44,8 @@ public function testGivenUserAlreadyHaveAPassword_UpdateUserPassword(): void ->missing('data.password') ->etc() ); + + Notification::assertSentTo($user, PasswordUpdatedNotification::class); } public function testNewPasswordFieldShouldBeRequired(): void