use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken 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.VerificationToken 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.VerificationToken in project lumberjack by fn-ctional.
the class UserService method createVerificationToken.
@Override
public void createVerificationToken(AdminUser user, String token) {
VerificationToken myToken = new VerificationToken(token, user);
authenticationBackend.addToken(myToken);
}
use of uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken 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.VerificationToken in project lumberjack by fn-ctional.
the class UserService method generateNewVerificationToken.
@Override
public VerificationToken generateNewVerificationToken(final String existingVerificationToken) throws SQLException {
VerificationToken vToken = authenticationBackend.findByToken(existingVerificationToken);
vToken.setToken(UUID.randomUUID().toString());
vToken = authenticationBackend.save(vToken);
return vToken;
}
Aggregations