Skip to content

Commit

Permalink
feat: Admin reset password email is now configured.
Browse files Browse the repository at this point in the history
* Admin model is now overriding the parent method sendPasswordResetNotification from the trait `CanResetPassword` but using custom logic.

* We have configured the `AdminResetPasswordNotification.php` `toMail` method.
  • Loading branch information
ahmadhuss committed May 14, 2021
1 parent 54de069 commit bcbeffc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/Models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Notifications\AdminResetPasswordNotification;

class Admin extends Authenticatable
{
Expand Down Expand Up @@ -39,4 +40,10 @@ class Admin extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

// We are overriding the sendPasswordRestNotification email
public function sendPasswordResetNotification($token)
{
$this->notify(new AdminResetPasswordNotification($token));
}
}
13 changes: 9 additions & 4 deletions app/Notifications/AdminResetPasswordNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ class AdminResetPasswordNotification extends Notification
{
use Queueable;

public $token;

/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
public function __construct($token)
{

$this->token = $token;
}

/**
Expand All @@ -40,9 +42,12 @@ public function via($notifiable)
*/
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.
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('You request to reset your password.')
->action('Reset Password Action', route('admin.password.reset', $this->token))
->line('Thank you for using our application!');
}

Expand Down
6 changes: 6 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
Route::post('password/email', [AdminForgotPasswordController::class, 'sendResetLinkEmail'])->name('admin.password.email'); // The email.blade.php form file will use this route to send post request.


// Important:
// AdminResetPasswordNotification.php `toMail()` linked to this route.
// This route will be translated in the email which we will send to others.
Route::get('password/reset/{token}', function (){})->name('admin.password.reset');


});

// This group is for the protection of admin authentication routes and uses `auth.admin`
Expand Down

0 comments on commit bcbeffc

Please sign in to comment.