use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException in project lumberjack by fn-ctional.
the class AuthenticationController method registerUserAccount.
@PostMapping("/registration")
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid AdminUserDTO accountDTO, BindingResult result, WebRequest request, Errors errors, Model model) {
if (result.hasErrors()) {
return new ModelAndView("registration", "user", accountDTO);
}
try {
AdminUser registered = createUserAccount(accountDTO, result);
String appUrl = request.getContextPath();
eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl));
model.addAttribute("messageType", "Registration");
model.addAttribute("messageString", "Check your emails for a verification link!");
} catch (EmailNotPermittedException e) {
model.addAttribute("messageType", "Failed Registration");
model.addAttribute("messageString", "You are not permitted to create an account.");
} catch (EmailExistsException e) {
model.addAttribute("messageType", "Failed Registration");
model.addAttribute("messageString", "A user with this email address has already registered.");
} catch (Exception e) {
e.printStackTrace();
model.addAttribute("messageType", "Registration Error");
model.addAttribute("messageString", "Your registration failed!");
}
return new ModelAndView("message", "user", accountDTO);
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException in project lumberjack by fn-ctional.
the class UserService method registerNewUserAccount.
@Transactional
@Override
public AdminUser registerNewUserAccount(AdminUserDTO accountDTO) throws EmailNotPermittedException, EmailExistsException, SQLException {
if (authenticationBackend.userExists(accountDTO.getEmail())) {
throw new EmailExistsException("There is already an account with that email address: " + accountDTO.getEmail());
}
if (!authenticationBackend.emailPermitted(accountDTO.getEmail())) {
throw new EmailNotPermittedException("The following email is not on the list of permitted emails: " + accountDTO.getEmail());
}
AdminUser user = new AdminUser();
user.setName(accountDTO.getName());
user.setPassword(passwordEncoder.encode(accountDTO.getPassword()));
user.setEmail(accountDTO.getEmail());
user.setEnabled(false);
authenticationBackend.addAdminUser(user);
return user;
}
Aggregations