use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class AuthenticationController method confirmRegistration.
@GetMapping(value = "/registrationConfirm")
public String confirmRegistration(WebRequest request, Model model, @RequestParam("token") String token) {
VerificationToken verificationToken = userService.getVerificationToken(token);
if (verificationToken == null) {
model.addAttribute("messageType", "Bad Verification Link");
model.addAttribute("messageString", "Try and register again.");
return "message";
}
AdminUser user = verificationToken.getAdminUser();
Calendar cal = Calendar.getInstance();
if ((verificationToken.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
model.addAttribute("messageType", "Token Expired");
model.addAttribute("messageString", "Your verification token expired, try to register again.");
model.addAttribute("expired", true);
model.addAttribute("token", token);
return "message";
}
user.setEnabled(true);
try {
userService.saveRegisteredUser(user);
model.addAttribute("messageType", "Registration Successful");
model.addAttribute("messageString", "You can now login.");
return "message";
} catch (SQLException e) {
model.addAttribute("messageType", "Database Error");
model.addAttribute("messageString", "Sorry! Try and register again.");
return "message";
} catch (MailAuthenticationException e) {
model.addAttribute("messageType", "Email Server Error");
model.addAttribute("messageString", "Sorry! Try and register again.");
return "message";
} catch (Exception e) {
model.addAttribute("messageType", "Unknown Server Error");
model.addAttribute("messageString", "Sorry! Try and register again.");
return "message";
}
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class AuthenticationController method resendRegistrationToken.
@GetMapping(value = "/user/resendRegistrationToken")
@ResponseBody
public ModelAndView resendRegistrationToken(HttpServletRequest request, @RequestParam("token") String existingToken, Model model) {
try {
VerificationToken newToken = userService.generateNewVerificationToken(existingToken);
AdminUser user = userService.getUser(newToken.getToken());
String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
SimpleMailMessage email = constructResendVerificationTokenEmail(appUrl, request.getLocale(), newToken, user);
mailSender.send(email);
model.addAttribute("messageType", "Successfully resent!");
model.addAttribute("messageString", "Please check your inbox!");
} catch (SQLException e) {
model.addAttribute("messageType", "Database Error!");
model.addAttribute("messageString", "Please try again.");
} catch (Exception e) {
model.addAttribute("messageType", "Unknown Server Error!");
model.addAttribute("messageString", "Please try again.");
}
return new ModelAndView("message", "user", hashCode());
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class MyUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
final Logger log = LoggerFactory.getLogger(LumberjackApplication.class);
AdminUser user = authenticationBackend.findByEmail(email);
log.info(email);
log.info(user.getEmail());
if (user.isEnabled()) {
log.info("enabled");
} else {
log.info("disabled");
}
boolean enabled = user.isEnabled();
final boolean accountNonExpired = true;
final boolean credentialsNonExpired = true;
final boolean accountNonLocked = true;
return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(Collections.singletonList("ADMINISTRATOR")));
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class DatabaseAdminUsers method loadAdminUserFromResultSet.
private AdminUser loadAdminUserFromResultSet(ResultSet rs) throws UsernameNotFoundException, SQLException {
if (rs.next()) {
AdminUser adminUser = new AdminUser();
adminUser.setEmail(rs.getString("Email"));
adminUser.setPassword(rs.getString("Password"));
adminUser.setName(rs.getString("Username"));
adminUser.setEnabled(rs.getBoolean("Enabled"));
return adminUser;
}
return null;
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser in project lumberjack by fn-ctional.
the class DatabaseAdminUsers method loadAdminUser.
public AdminUser loadAdminUser(String email) throws UsernameNotFoundException, SQLException {
PreparedStatement stmt = databaseConnection.getConnection().prepareStatement("SELECT * FROM Admins WHERE Email = ?");
stmt.setString(1, email);
ResultSet rs = stmt.executeQuery();
AdminUser adminUser = loadAdminUserFromResultSet(rs);
if (adminUser == null)
throw new UsernameNotFoundException("Username not found: " + email);
return adminUser;
}
Aggregations