From bcbeffc3f4d181104c12dea9bff5644393f2016b Mon Sep 17 00:00:00 2001 From: ahmadhuss Date: Fri, 14 May 2021 17:42:01 +0500 Subject: [PATCH] feat: Admin reset password email is now configured. * 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. --- app/Models/Admin.php | 7 +++++++ .../AdminResetPasswordNotification.php | 13 +++++++++---- routes/web.php | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/Models/Admin.php b/app/Models/Admin.php index 24ae4ca..52515a4 100644 --- a/app/Models/Admin.php +++ b/app/Models/Admin.php @@ -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 { @@ -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)); + } } diff --git a/app/Notifications/AdminResetPasswordNotification.php b/app/Notifications/AdminResetPasswordNotification.php index c85645e..180e01c 100644 --- a/app/Notifications/AdminResetPasswordNotification.php +++ b/app/Notifications/AdminResetPasswordNotification.php @@ -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; } /** @@ -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!'); } diff --git a/routes/web.php b/routes/web.php index d0053b1..1a9e29e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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`