Package com.ericbouchut.learndev.auth
Class RegistrationService
java.lang.Object
com.ericbouchut.learndev.auth.RegistrationService
Creates new user accounts: enforces unique username and email, hashes the
password, and assigns the default
STUDENT role.-
Constructor Summary
ConstructorsConstructorDescriptionRegistrationService(UserRepository users, RoleRepository roles, org.springframework.security.crypto.password.PasswordEncoder encoder) -
Method Summary
Modifier and TypeMethodDescriptionregister(RegisterForm form) Registers a new account with the defaultSTUDENTrole.register(RegisterForm form, String roleName) Registers a new account with the given seeded role (self-registration usesSTUDENT; the admin area createsINSTRUCTORaccounts).
-
Constructor Details
-
RegistrationService
public RegistrationService(UserRepository users, RoleRepository roles, org.springframework.security.crypto.password.PasswordEncoder encoder)
-
-
Method Details
-
register
Registers a new account with the defaultSTUDENTrole. The password is hashed before being stored; the raw password is never persisted.- Parameters:
form- the validated registration form- Returns:
- the saved user, including its generated id
- Throws:
DuplicateUsernameException- if the username is already takenDuplicateEmailException- if the email is already registered
-
register
Registers a new account with the given seeded role (self-registration usesSTUDENT; the admin area createsINSTRUCTORaccounts). Same uniqueness and hashing rules asregister(com.ericbouchut.learndev.auth.dto.RegisterForm).- Parameters:
form- the validated registration formroleName- the seeded role to assign- Returns:
- the saved user, including its generated id
- Throws:
DuplicateUsernameException- if the username is already takenDuplicateEmailException- if the email is already registered
-