diff --git a/config/auth.php b/config/auth.php index ad7abf9..d5abfb7 100644 --- a/config/auth.php +++ b/config/auth.php @@ -17,17 +17,18 @@ /* |-------------------------------------------------------------------------- - | Login Validation + | Forgot Password |-------------------------------------------------------------------------- | | This value will be used to across system where model is needed | Exclude auth fields | Example: reset_link, otp, temporary_password */ - - 'password_reset_method' => '', + 'self_password_reset' => true, + 'password_reset_method' => 'otp', 'temporary_password_length' => 8, + /* |-------------------------------------------------------------------------- | Permission Model diff --git a/routes/api.php b/routes/api.php index 79156a8..777c7ee 100644 --- a/routes/api.php +++ b/routes/api.php @@ -27,13 +27,16 @@ ->middleware('guest') ->name('login'); - Route::post('/forgot-password', [PasswordResetController::class, 'store']) - ->middleware('guest') - ->name('forgot-password'); + if (config('fintech.auth.self_password_reset')) { - Route::post('/reset-password', [PasswordResetController::class, 'update']) - ->middleware('guest') - ->name('reset-password'); + Route::post('/forgot-password', [PasswordResetController::class, 'store']) + ->middleware('guest') + ->name('forgot-password'); + + Route::post('/reset-password', [PasswordResetController::class, 'update']) + ->middleware('guest') + ->name('reset-password'); + } Route::get('/verify-email/{id}/{hash}', VerifyEmailController::class) ->middleware(['auth', 'signed', 'throttle:6,1']) diff --git a/src/Notifications/SendPasswordResetNotification.php b/src/Notifications/PasswordResetNotification.php similarity index 70% rename from src/Notifications/SendPasswordResetNotification.php rename to src/Notifications/PasswordResetNotification.php index 64c8288..f52e1b8 100644 --- a/src/Notifications/SendPasswordResetNotification.php +++ b/src/Notifications/PasswordResetNotification.php @@ -6,7 +6,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class SendPasswordResetNotification extends Notification +class PasswordResetNotification extends Notification { use Queueable; @@ -39,36 +39,38 @@ public function via(object $notifiable): array */ public function toMail(object $notifiable): MailMessage { + logger('payload', $this->data); + $mailable = (new MailMessage) ->line('You recently requested to reset the password for your ' . ucwords(config('app.name')) . ' account.'); if ($this->data['method'] == 'temporary_password') - $mailable->lines([ - 'Your account existing password as been reset.', - 'We have sent you a completely automated and randomized password as you requested', - 'System or authority does not a plain copy of this information and password will expired within ' - . config('auth.passwords.users.expire') . 'minutes.', - 'Please log into your account using the temporary password, and reset after first successful logged in.', - 'Your account new password will be **' . $this->data['value'] . '**', + $mailable = $mailable->lines([ + 'We have sent you a completely automated and randomized password as you requested. + System or authority does not a plain copy of this information and password will expired within ' + . config('auth.passwords.users.expire') . ' minutes. + Please log into your account using the temporary password afterwards reset after first successful logged in.', + '', + 'Your account new password will be `' . $this->data['value'] . '`', ]) ->action('Log into Account', $this->data['url']) ->line('If you did not request a password reset, Please contact system administrator for further action.'); elseif ($this->data['method'] == 'reset_link') - $mailable->lines([ - 'No changes have been made to your account yet.', + $mailable = $mailable->lines([ + '**No changes have been made to your account yet.**', 'System or authority does not a plain copy of this information and reset link will expired within ' - . config('auth.passwords.users.expire') . 'minutes.', - 'Click the button below to proceed.']) + . config('auth.passwords.users.expire') . ' minutes. + Click the button below to proceed.']) ->action('Reset Password', $this->data['url']) ->line('If you did not request a password reset, no further action is required.'); elseif ($this->data['method'] == 'otp') - $mailable->lines([ - 'No changes have been made to your account yet.', - 'System or authority does not a plain copy of this information and *One Time Password* verification - will expired within ' . config('auth.passwords.users.expire') . 'minutes.' + $mailable = $mailable->lines([ + '**No changes have been made to your account yet.**', + 'System or authority does not a plain copy of this information and **One Time Password** verification + will expired within ' . config('auth.passwords.users.expire') . ' minutes.' ]) ->line("Your account verification OTP is: *{$this->data['value']}*") ->line('If you did not request a password reset, no further action is required.'); diff --git a/src/Services/OneTimePinService.php b/src/Services/OneTimePinService.php index 5b9f68e..70362d8 100644 --- a/src/Services/OneTimePinService.php +++ b/src/Services/OneTimePinService.php @@ -3,7 +3,7 @@ namespace Fintech\Auth\Services; use Fintech\Auth\Interfaces\OneTimePinRepository; -use Fintech\Auth\Notifications\SendPasswordResetNotification; +use Fintech\Auth\Notifications\PasswordResetNotification; /** * Class PermissionService @@ -42,7 +42,7 @@ public function create($user) $token = (string)mt_rand($min, $max); if($otp = $this->oneTimePinRepository->create($authField, $token)) { - $user->notify(new SendPasswordResetNotification($otp)); + $user->notify(new PasswordResetNotification($otp)); } return true; diff --git a/src/Services/PasswordResetService.php b/src/Services/PasswordResetService.php index 9335903..0c7a41c 100644 --- a/src/Services/PasswordResetService.php +++ b/src/Services/PasswordResetService.php @@ -4,7 +4,7 @@ use Fintech\Auth\Facades\Auth; use Fintech\Auth\Interfaces\OneTimePinRepository; -use Fintech\Auth\Notifications\SendPasswordResetNotification; +use Fintech\Auth\Notifications\PasswordResetNotification; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; @@ -67,7 +67,7 @@ public function notify($user) if ($notification_data['status']) { - $user->notify(new SendPasswordResetNotification($notification_data)); + $user->notify(new PasswordResetNotification($notification_data)); return ['message' => $notification_data['message'], 'status' => true]; }