Package com.example.demo.registration
Class RegistrationService
java.lang.Object
com.example.demo.registration.RegistrationService
Service class that handles the user registration process.
It handles input validation, user account creation, generating and persisting
confirmation tokens, and sending the verification email.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconfirmToken(String token) Confirms the account registration using a valid token.register(RegistrationRequest request) Processes a new user registration request.
-
Constructor Details
-
RegistrationService
public RegistrationService()
-
-
Method Details
-
register
Processes a new user registration request.1. Validates the email format. 2. Creates and saves the new
AppUserwith a default role (USER). 3. Generates a unique confirmation token. 4. Sends a confirmation email to the user.- Parameters:
request- TheRegistrationRequestDTO containing user details.- Returns:
- The unique confirmation token string.
- Throws:
IllegalStateException- if the email format is invalid.
-
confirmToken
Confirms the account registration using a valid token.1. Retrieves the ConfirmationToken. 2. Checks if the token is already confirmed or expired. 3. If valid, updates the token's confirmedAt timestamp. 4. Enables the associated AppUser account.
- Parameters:
token- The confirmation token string provided by the user.- Returns:
- A string literal "confirmed" upon successful account activation.
- Throws:
IllegalStateException- if the token is not found, already confirmed, or expired.
-