Skip to content

Commit

Permalink
refactor: Now forgotten password email also includes token with email
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadhuss committed May 14, 2021
1 parent bcbeffc commit 1b1a544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/Models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Admin extends Authenticatable
// We are overriding the sendPasswordRestNotification email
public function sendPasswordResetNotification($token)
{
$this->notify(new AdminResetPasswordNotification($token));
// `$this` has instance of the model so we get the email attribute value and pass to the
// notification so it includes also the email in the Mail that we will send.
$this->notify(new AdminResetPasswordNotification($token, $this->email));
}
}
11 changes: 8 additions & 3 deletions app/Notifications/AdminResetPasswordNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ class AdminResetPasswordNotification extends Notification
use Queueable;

public $token;
public $email;

/**
* Create a new notification instance.
*
* @return void
* @param $token
* @param null $email
*/
public function __construct($token)
public function __construct($token, $email = null)
{
$this->token = $token;
$this->email = $email;
}

/**
Expand All @@ -45,9 +48,11 @@ public function toMail($notifiable)
// Currently, In our action method:
// The "admin.password.reset" route is the unique route that receiver will receive through email.
// This receive email will contains user email & token.
// route('admin.password.reset', $this->token)) translates into http://localhost/admin/password/reset/033860c11059dcc4c
// route('admin.password.reset', [$this->token, 'email' => $this->email]) translates into http://localhost/admin/password/reset/033860c11059dcc4c?email=h@h.com
return (new MailMessage)
->line('You request to reset your password.')
->action('Reset Password Action', route('admin.password.reset', $this->token))
->action('Reset Password Action', route('admin.password.reset', [$this->token, 'email' => $this->email]))
->line('Thank you for using our application!');
}

Expand Down

0 comments on commit 1b1a544

Please sign in to comment.