Skip to content

Commit

Permalink
send PasswordRest notification on successfull reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 12, 2021
1 parent dbb9468 commit 7b42b1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Containers\AppSection\Authentication\Notifications;

use App\Ship\Parents\Models\UserModel;
use App\Ship\Parents\Notifications\Notification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class PasswordReset extends Notification implements ShouldQueue
{
use Queueable;

public function via($notifiable): array
{
return ['mail'];
}

public function toMail(UserModel $notifiable): MailMessage
{
return (new MailMessage())
->subject('Password Reset')
->line('Your password has been reset successfully.');
}
}

0 comments on commit 7b42b1f

Please sign in to comment.