From 430762f4d5f0678d7580b10510fefc581efb2ca3 Mon Sep 17 00:00:00 2001 From: egmp777 Date: Mon, 1 Dec 2014 12:11:06 -0500 Subject: [PATCH] Email Confirmation Article When VerificationToken expires Redirect to error page --- .../baeldung/security/MyUserDetailsService.java | 4 ---- .../web/controller/RegistrationController.java | 3 ++- .../src/main/resources/application.properties | 14 +++++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/security/MyUserDetailsService.java b/spring-security-login-and-registration/src/main/java/org/baeldung/security/MyUserDetailsService.java index f1896ab3d7..e75cb4fa7b 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/security/MyUserDetailsService.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/security/MyUserDetailsService.java @@ -51,10 +51,6 @@ public class MyUserDetailsService implements UserDetailsService { enabled = false; return new org.springframework.security.core.userdetails.User(" ", " ", enabled, true, true, true, getAuthorities(new Integer(1))); } - if (user.isTokenExpired()) { - accountNonExpired = false; - return new org.springframework.security.core.userdetails.User(" ", " ", enabled, accountNonExpired, true, true, getAuthorities(new Integer(1))); - } return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword().toLowerCase(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(user.getRole().getRole())); } catch (Exception e) { diff --git a/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java b/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java index 211ea95c1f..fe22f25bf2 100644 --- a/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java +++ b/spring-security-login-and-registration/src/main/java/org/baeldung/web/controller/RegistrationController.java @@ -64,7 +64,8 @@ public class RegistrationController { User user = verificationToken.getUser(); Calendar cal = Calendar.getInstance(); if ((verificationToken.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) { - user.setTokenExpired(true); + model.addAttribute("message", messages.getMessage("auth.message.expired", null, request.getLocale())); + return "redirect:/badUser.html?lang=" + request.getLocale().getLanguage(); } user.setEnabled(true); service.saveRegisteredUser(user); diff --git a/spring-security-login-and-registration/src/main/resources/application.properties b/spring-security-login-and-registration/src/main/resources/application.properties index baf7f37034..51db801043 100644 --- a/spring-security-login-and-registration/src/main/resources/application.properties +++ b/spring-security-login-and-registration/src/main/resources/application.properties @@ -1,17 +1,17 @@ ################### DataSource Configuration ########################## jdbc.driverClassName=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/AUTHDATA -jdbc.user=root -###jdbc.pass=admin### +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_02?createDatabaseIfNotExist=true +jdbc.user=tutorialuser +jdbc.pass=tutorialmy5ql init-db=false ################### Hibernate Configuration ########################## hibernate.dialect=org.hibernate.dialect.MySQLDialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=validate +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop ################### JavaMail Configuration ########################## smtp.host=smtp.gmail.com smtp.port=465 smtp.protocol=smtps -smtp.username=xxx@gmail.com +smtp.username=xxx777@gmail.com smtp.password= -support.email=xxx@gmail.com \ No newline at end of file +support.email=xxx777@gmail.com \ No newline at end of file