use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class DatabaseTokens method loadTokenFromResultSet.
private VerificationToken loadTokenFromResultSet(ResultSet rs) throws SQLException {
if (rs.next()) {
AdminUser adminUser = databaseAdminUsers.loadAdminUser(rs.getString("AdminEmail"));
String token = rs.getString("Token");
return new VerificationToken(token, adminUser);
}
return null;
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class WebController method dashboard.
/**
* GET request handler for serving the admin dashboard with the active user's name as a model attribute.
* @param model
* @return
*/
@GetMapping("/dashboard")
public String dashboard(Model model) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String email = auth.getName();
AdminUser user = authenticationBackend.findByEmail(email);
String name = user.getName();
model.addAttribute("name", name);
return "dashboard";
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser 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.authentication.data.AdminUser 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;
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class RegistrationListener method confirmRegistration.
private void confirmRegistration(OnRegistrationCompleteEvent event) {
AdminUser adminUser = event.getAdminUser();
String token = UUID.randomUUID().toString();
service.createVerificationToken(adminUser, token);
String recipientAddress = adminUser.getEmail();
String subject = "Registration Confirmation";
String confirmationUrl = event.getAppUrl() + "/registrationConfirm?token=" + token;
String message = "Registration Successful ";
SimpleMailMessage email = new SimpleMailMessage();
email.setTo(recipientAddress);
email.setSubject(subject);
email.setText(message + "<a href=\"" + "http://localhost:8080" + confirmationUrl + "\"\\a>");
email.setFrom(env.getProperty("support.email"));
final Logger log = LoggerFactory.getLogger(LumberjackApplication.class);
log.info("About to send email!");
mailSender.send(email);
}
Aggregations