From 4e15d1e85d6e795530653ba8d5a007a5ed4690ae Mon Sep 17 00:00:00 2001 From: Jeremy Quinton Date: Tue, 2 Oct 2018 17:29:57 +0200 Subject: [PATCH] fixes #470 Fixes the forgotten password link --- app/Http/Controllers/RemindersController.php | 4 +- app/Http/routes.php | 1 + app/Models/User.php | 15 ++++- app/Notifications/UserResetPassword.php | 66 +++++++++++++++++++ config/app.php | 2 + .../views/en/Emails/Auth/Reminder.blade.php | 2 +- 6 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 app/Notifications/UserResetPassword.php diff --git a/app/Http/Controllers/RemindersController.php b/app/Http/Controllers/RemindersController.php index bee00663..5de2e1a6 100644 --- a/app/Http/Controllers/RemindersController.php +++ b/app/Http/Controllers/RemindersController.php @@ -59,9 +59,7 @@ class RemindersController extends Controller { $this->validate($request, ['email' => 'required']); - $response = $this->passwords->sendResetLink($request->only('email'), function ($m) { - $m->subject($this->getEmailSubject()); - }); + $response = $this->passwords->sendResetLink($request->only('email')); switch ($response) { case PasswordBroker::RESET_LINK_SENT: diff --git a/app/Http/routes.php b/app/Http/routes.php index bab078fa..b1e286dc 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -82,6 +82,7 @@ Route::group( 'as' => 'showResetPassword', 'uses' => 'RemindersController@getReset', ]); + ])->name('password.reset'); Route::post('login/reset-password', [ 'as' => 'postResetPassword', diff --git a/app/Models/User.php b/app/Models/User.php index f0e3196a..a165d94a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,16 +2,18 @@ namespace App\Models; +use App\Notifications\UserResetPassword; use Illuminate\Auth\Authenticatable; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Notifications\Notifiable; class User extends Model implements AuthenticatableContract, CanResetPasswordContract { - use Authenticatable, CanResetPassword, SoftDeletes; + use Authenticatable, CanResetPassword, SoftDeletes, Notifiable; /** * The database table used by the model. @@ -155,4 +157,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon $user->api_token = str_random(60); }); } + + /** + * Send the password reset notification. + * + * @param string $token + * @return void + */ + public function sendPasswordResetNotification($token) + { + $this->notify(new UserResetPassword($token)); + } } diff --git a/app/Notifications/UserResetPassword.php b/app/Notifications/UserResetPassword.php new file mode 100644 index 00000000..a68e309c --- /dev/null +++ b/app/Notifications/UserResetPassword.php @@ -0,0 +1,66 @@ +token = $token; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + + $mailMessage = new MailMessage(); + $mailMessage->view('Emails.Auth.Reminder', ['token' => $this->token]); + + return ($mailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/config/app.php b/config/app.php index ed91f951..efbd3c17 100644 --- a/config/app.php +++ b/config/app.php @@ -146,6 +146,7 @@ return [ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, + Illuminate\Notifications\NotificationServiceProvider::class, /* * Application Service Providers... @@ -206,6 +207,7 @@ return [ 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, 'Password' => Illuminate\Support\Facades\Password::class, + 'Notification' => Illuminate\Support\Facades\Notification::class, 'Queue' => Illuminate\Support\Facades\Queue::class, 'Redirect' => Illuminate\Support\Facades\Redirect::class, 'Redis' => Illuminate\Support\Facades\Redis::class, diff --git a/resources/views/en/Emails/Auth/Reminder.blade.php b/resources/views/en/Emails/Auth/Reminder.blade.php index acd6ec5e..ca3536f1 100644 --- a/resources/views/en/Emails/Auth/Reminder.blade.php +++ b/resources/views/en/Emails/Auth/Reminder.blade.php @@ -3,7 +3,7 @@ @section('message_content')
Hello,

- To reset your password, complete this form: {{ route('showResetPassword', ['token' => $token]) }}. + To reset your password, complete this form: {{ route('password.reset', ['token' => $token]) }}.


Thank you,
Team Attendize