Search in sources :

Example 1 with VerificationToken

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";
    }
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) SQLException(java.sql.SQLException) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)

Example 2 with VerificationToken

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());
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) SQLException(java.sql.SQLException) ModelAndView(org.springframework.web.servlet.ModelAndView) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) EmailNotPermittedException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException) MailAuthenticationException(org.springframework.mail.MailAuthenticationException) SQLException(java.sql.SQLException) EmailExistsException(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)

Example 3 with VerificationToken

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);
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken)

Example 4 with VerificationToken

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;
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser)

Example 5 with VerificationToken

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;
}
Also used : VerificationToken(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken)

Aggregations

VerificationToken (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.VerificationToken)5 AdminUser (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser)3 SQLException (java.sql.SQLException)2 MailAuthenticationException (org.springframework.mail.MailAuthenticationException)2 EmailExistsException (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailExistsException)2 EmailNotPermittedException (uk.ac.bris.cs.rfideasalreadytaken.lumberjack.exceptions.EmailNotPermittedException)2 Calendar (java.util.Calendar)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1