Forgot My Password Fixes – Native Laravel 5.4 Multiple Authentication Series (Part 5)

テクノロジー



Finishing up our series on multi-user authentication in Laravel, it is time to make sure that the “Forgot My Password” functionality works for our new user type.

It should already work out of the box for the main default user type (as defined in config/auth.php) but we need to do some serious work to get it to do its magic for our other user type. In this video the secondary user type is called “Admins”, so that is what you will see here.

These are the steps of what we need to do:
1) Duplicate the two controllers that manage our password resets
2) Make sure to match the classnames to the file names for these controllers
3) Set the broker for both of these controllers by creating a protected broker() function
4) Set the middleware for both of these controllers to be the guest middleware FOR OUR GUARD. For example guest:admin.
5) In the ResetPasswordController copy we also need to set the guard in a protected guard() function and also set the redirect url (for the final step of the password reset) by defining the protected $redirectTo property
6) Copy the 4 routes for password resets and make “admin” versions of all of them (we do this by prefixing “admin” to all of the routes)
6) Duplicate the two views in our views/auth/password directory
7) Make sure you update each view’s forms to submit to the new admin routes instead of the original routes
8) Back in the ForgotPasswordController we want to override the showLinkRequestForm() method and make sure that it returns the new view we created email-admin.blade.php
9) Now we need to go to our Admin model and override the sendPasswordResetNotification() method and have it use our new notification that we will set up next
10) In the terminal, create a new notification named AdminResetPasswordNotification
11) Open the new notification file and update the text of the email to say what you want. Also create a public property $token and set that property equal to the $token that we pass into it on __construct().
12) Finally finish the notification by setting the link in the notification equal to our step 3 route and attaching the new token property to the end of the url
13) Now in the ResetPasswordController we need to override showResetForm() method to have it return our view reset-admin.blade.php

Yay you are done! Test it out.

—— WRITTEN TUTORIAL: (Coming Soon)

===========================================
=== Multiple Authentication in Laravel 5.4 Series: ===
===========================================
Part 1: Setting up our Models and Auth Guards

Part 2: Creating Login Pages and Logging in Users

Part 3: Modifying Middleware to Support Multiple Users

Part 4: Logging Out Multiple User Types

Part 5: Forgot My Password Functionality across Multiple User Types

==== DOWNLOAD SOURCE CODE ====

Download from GitHub:
https://github.com/DevMarketer/multiauth_tutorial/releases/tag/part_5

==== FOLLOW ME ====

Subscribe to DevMarketer Insider
https://confirmsubscription.com/h/d/5EDC91CF554832D1

Twitter – http://twitter.com/_jacurtis
(ask me questions!)

==== QUESTIONS? ====

Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.

Email me hello@jacurtis.com

Thanks for all your support!

_________
Laravel 5.4 Authentication Multiple User Models One Application. Best tutorial authentication laravel help. Laravel 5.3 Muliple Authentication. No Packages. Laravel Php code tutorial video post example. Store user admins. Multiauth tutorial.

Comments

Copied title and URL