Class RegistrationService

java.lang.Object
com.ericbouchut.learndev.auth.RegistrationService

@Service public class RegistrationService extends Object
Creates new user accounts: enforces unique username and email, hashes the password, and assigns the default STUDENT role.
  • Constructor Details

    • RegistrationService

      public RegistrationService(UserRepository users, RoleRepository roles, org.springframework.security.crypto.password.PasswordEncoder encoder)
  • Method Details

    • register

      @Transactional public User register(RegisterForm form)
      Registers a new account with the default STUDENT role. 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 taken
      DuplicateEmailException - if the email is already registered
    • register

      @Transactional public User register(RegisterForm form, String roleName)
      Registers a new account with the given seeded role (self-registration uses STUDENT; the admin area creates INSTRUCTOR accounts). Same uniqueness and hashing rules as register(com.ericbouchut.learndev.auth.dto.RegisterForm).
      Parameters:
      form - the validated registration form
      roleName - the seeded role to assign
      Returns:
      the saved user, including its generated id
      Throws:
      DuplicateUsernameException - if the username is already taken
      DuplicateEmailException - if the email is already registered