Skip to content

Commit

Permalink
LP-4 send forgot password reset mail is done
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Oct 16, 2023
1 parent 71d3197 commit a692a1e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
7 changes: 4 additions & 3 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SendPasswordResetNotification extends Notification
class PasswordResetNotification extends Notification
{
use Queueable;

Expand Down Expand Up @@ -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.');
Expand Down
4 changes: 2 additions & 2 deletions src/Services/OneTimePinService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Services/PasswordResetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit a692a1e

Please sign in to comment.