top of page
Search

Registration, email verification and login

  • Nov 9, 2022
  • 2 min read

Updated: Dec 13, 2022

Laravel/ui package generates various pre-built authentication controllers as well as layout view, registration, and login views. It also generates HomeController to handle post-login request to application dashboard.

Many web application require users to verify their email address, In the older version of Laravel the user has to manually do the email verification; However, after version 5.8 Laravel always provide in-build setup of email verification.

ree

LoginController – handles authentication


ree

RegisterController – handles new user registration


ForgotPasswordController – handles e-mailing links for resetting passwords

ResetPasswordController – handles reset passwords


ree

verificationController - handle email verification for user newly registered.


Laravel provide built-in services for sending and verifying email verification request.


Model set up

At the user model import the Illuminate\Contracts\Auth\MustVerifyEmail, then add implements MustverifyEmail in user class.

ree

After changes, newly registered users will automatically receive email which contain an email verification link.


Route

App\Providers\RouteServiceProvider is one of the key service provider that loads the route files contain within routes directory. once all service providers have been registered, the router handed off the request for dispatching to controller as well as run any route specific middleware.

middleware filtering HTTP requests, if the user being authenticated middleware verify it, then the route or controller method will be implement and response.


Auth::routes(['verify'=>true]);

ree

At web.php pass an array to tell the route email must be verified.


From App\Http\Controllers;


$this->middleware(['auth', 'verified']);

ree

Pass an array to tell middleware to make sure user authenticate and their email must be verified.


Mailtrap – email testing tool

Mailtrap email delivery platform provides a fake SMTP server for testing purpose to view and share emails, and test with real data without the risk of spamming. Mailtrap catches all the test message and keeps them in its inbox, After inspecting spam score, CSS, HTML and more, the developer can use email API or SMPT relay to send emails.

ree

This is done by copying above values and paste them in .env file configure the mailing configuration.

ree

For better performance optimize the framework.

php artisan optimize or php artisan optimize:clear


now let's test the email verification.

By using php artisan serve command the application will accessible in browser at http://localhost:80000.


ree

Register new user.


ree

When users register, before getting to dashboard, they need to verify their email address.


ree

As you can see in the above image, email verification has been sent to mailtrap.

ree

After user verifying the email address the user will get to dashboard.


 
 
 

Recent Posts

See All
Project Introduction

In this Project, I am looking to develop a Laravel web application for contact list and host it on a public web server. The project has...

 
 
 

Comments


Thanks for submitting!

© 2023 by DO IT YOURSELF. Proudly created with Wix.com

bottom of page