Spring Boot Login and Registration to PostgreSQL Database with Email Verification Api
- Scenario: following is the complete backend application for user login and registration using Spring Boot which also includes email verification link. So person comes to register with the firstname, lastname, email and password. Which are then saved on Database. In fact, user gets authorization token back from the server as the proof of registration. Then there goes email verification link to the user's email with the expiration period of 15 minute.
- First we create new Spring project with
Spring Initializer
by using theIntelliJ IDEA
as following:
- After that, we set required dependencies and Spring Boot version:
- We run the Spring application first:
-
Then with the
Postman
client we send new user registration request as following: -
After successful registration, we can check the Database:
- And on Postman we get
token
from the server as the meaning of successful registration:
- To simulate the email verification part, we use maildev which is the simple way to test project's generated email during development, with an easy to use web interface that runs on local machine built on top of Node.js:
# first clone the GitHub repository
$ git clone https://github.com/maildev/maildev.git
# then run the following command
$ npm install -g maildev
- Then we can check successful installation by running
maildev
:
- maildev page looks as following:
- Then when we press the
Activate Now
, it redirects to the confirmation page: