User Story: As a user, I want to be able to register, log in, and log out of the application, so that I can access securely the application's features.
Description: Implement a secure user authentication system to allow users to register, log in, and log out of the application. The system should also support password encryption and session management. More concretely:
Users should be able to register with an email and password.
Users should be able to log in using their registered email and password.
Users should be able to log out.
Passwords should be encrypted before being stored in the database.
The system should maintain user sessions for a seamless experience.
Design
Use Case for User Authentication
Actor: User
Preconditions: The user is not logged in.
Postconditions: The user is authenticated and logged in.
Main Flow:
The user navigates to the login page.
The user enters their email and password.
The system validates the credentials.
The user is redirected to the dashboard.
Alternative Flows:
Invalid Credentials:
The system displays an error message.
The user is prompted to re-enter their credentials.
Sequence Diagram for User Authentication:
sequenceDiagram
actor User
participant Frontend
participant AuthService
participant UserService
participant Database
User->>Frontend: Enter email and password
Frontend->>AuthService: validateUser(email, password)
AuthService->>UserService: findUserByEmail(email)
UserService->>Database: Query user by email
Database-->>UserService: Return user
UserService-->>AuthService: Return user
AuthService->>AuthService: Compare passwords
alt passwords match
AuthService-->>Frontend: Return JWT token
Frontend-->>User: Redirect to dashboard
else passwords do not match
AuthService-->>Frontend: Return error
Frontend-->>User: Display error message
end
In the sequence diagram, the flow starts with the user entering their email and password on the frontend. The frontend then calls the validateUser method in the AuthService, which in turn uses the UserService to find the user by email in the database. If the user is found, the AuthService compares the entered password with the stored password. If the passwords match, the user is authenticated, and a JWT token is returned to the frontend, which then redirects the user to the dashboard. If the passwords do not match, an error message is displayed to the user.
Overview
User Story: As a user, I want to be able to register, log in, and log out of the application, so that I can access securely the application's features.
Description: Implement a secure user authentication system to allow users to register, log in, and log out of the application. The system should also support password encryption and session management. More concretely:
Design
Use Case for User Authentication
Sequence Diagram for User Authentication:
In the sequence diagram, the flow starts with the user entering their email and password on the frontend. The frontend then calls the
validateUser
method in theAuthService
, which in turn uses theUserService
to find the user by email in the database. If the user is found, theAuthService
compares the entered password with the stored password. If the passwords match, the user is authenticated, and a JWT token is returned to the frontend, which then redirects the user to the dashboard. If the passwords do not match, an error message is displayed to the user.ERD for Database
UML for Backend
API Documentation
POST /auth/register
{ "email": "user@example.com", "password": "password123" }
{ "message": "User registered successfully." }
POST /auth/login
{ "email": "user@example.com", "password": "password123" }
{ "token": "JWT_TOKEN_HERE", "message": "Login successful." }
POST /auth/logout
{ "message": "Logout successful." }
Wireframes for Frontend
Tasks