From 2021a39229d362c35cad53fd7ef26a9e56ba409e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 12 Mar 2011 19:10:44 -0300 Subject: [PATCH] Add configurable email confirmation. --- .../controller/UserController.java | 19 ++++++++-- .../com/wisemapping/service/UserService.java | 2 +- .../wisemapping/service/UserServiceImpl.java | 36 ++++++++++++------- .../src/main/webapp/WEB-INF/app.properties | 6 +++- .../webapp/WEB-INF/wisemapping-servlet.xml | 14 +++++--- .../jsp/userRegistrationConfirmation.jsp | 35 ++++++++++-------- wise-webapp/src/test/data/freemind/basice.mm | 1 + 7 files changed, 77 insertions(+), 36 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java b/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java index 18fd7dd2..c8c5a1f1 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java @@ -33,15 +33,28 @@ import com.wisemapping.view.UserBean; import com.wisemapping.exceptions.WiseMappingException; import org.springframework.web.servlet.ModelAndView; +import java.util.HashMap; +import java.util.Map; + public class UserController extends CaptchaFormController { //~ Instance fields ...................................................................................... + private boolean emailConfirmEnabled; private UserService userService; //~ Methods .............................................................................................. + + public boolean isEmailConfirmEnabled() { + return emailConfirmEnabled; + } + + public void setEmailConfirmEnabled(boolean emailConfirmEnabled) { + this.emailConfirmEnabled = emailConfirmEnabled; + } + public ModelAndView onSubmit(Object command) throws WiseMappingException { final UserBean userBean = ((UserBean) command); @@ -53,10 +66,12 @@ public class UserController user.setFirstname(userBean.getFirstname()); user.setLastname(userBean.getLastname()); user.setPassword(userBean.getPassword()); - userService.createUser(user); + userService.createUser(user,emailConfirmEnabled); } - return new ModelAndView(getSuccessView()); + final Map model = new HashMap(); + model.put("confirmByEmail",emailConfirmEnabled); + return new ModelAndView(getSuccessView(),model); } public void setUserService(UserService userService) { diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java index 4aeed911..40887ce4 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java @@ -25,7 +25,7 @@ public interface UserService { public void activateAcount(long code) throws InvalidActivationCodeException; - public void createUser(User user) throws WiseMappingException; + public void createUser(User user, boolean emailConfirmEnabled) throws WiseMappingException; public void changePassword(User user); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java index dbf63dc3..e11c9653 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java @@ -38,8 +38,7 @@ public class UserServiceImpl final static Logger logger = Logger.getLogger("org.wisemapping.service"); public void activateAcount(long code) - throws InvalidActivationCodeException - { + throws InvalidActivationCodeException { final User user = userManager.getUserByActivationCode(code); if (user == null || user.isActive()) { throw new InvalidActivationCodeException("Invalid Activation Code"); @@ -67,7 +66,7 @@ public class UserServiceImpl changePassword(user); model.put("user", user); model.put("password", password); - + mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "WiseMapping : Recovery Password", model, "recoveryMail.vm"); } else { throw new InvalidUserEmailException("The email '" + email + "' does not exists."); @@ -91,30 +90,41 @@ public class UserServiceImpl return lo + i; } - public void createUser(User user) throws WiseMappingException { + public void createUser(User user, boolean emailConfirmEnabled) throws WiseMappingException { final UUID uuid = UUID.randomUUID(); user.setCreationDate(Calendar.getInstance()); - user.setActivationDate(null); user.setActivationCode(uuid.getLeastSignificantBits()); - Colaborator col = userManager.getColaboratorBy(user.getEmail()); - if (col != null) - { - userManager.createUser(user,col); + if (emailConfirmEnabled) { + user.setActivationDate(null); + + } else { + user.setActivationDate(Calendar.getInstance()); } - else - { + + Colaborator col = userManager.getColaboratorBy(user.getEmail()); + if (col != null) { + userManager.createUser(user, col); + } else { userManager.createUser(user); } //create welcome map mindmapService.addWelcomeMindmap(user); + // Send registration email. + if (emailConfirmEnabled) { + sendRegistrationEmail(user); + } + } + + private void sendRegistrationEmail(User user) { final Map model = new HashMap(); model.put("user", user); - // TODO: ver como no hacer hardcode el url + + final String activationUrl = "http://wisemapping.com/c/activation.htm?code=" + user.getActivationCode(); - logger.info("create User - acrivationUrl: "+activationUrl); + logger.info("create User - acrivationUrl: " + activationUrl); model.put("emailcheck", activationUrl); mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "Welcome to Wisemapping!", model, "confirmationMail.vm"); diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties index cce09215..c4cff7ce 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/app.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties @@ -13,7 +13,11 @@ database.hibernate.dialect=org.hibernate.dialect.HSQLDialect database.username=sa database.password= -# Mail configuration seccion. + +# Enable/Disable user confirmation by e-mail. If it's enabled, mail must be configured. +user.confirm.registration=false + +# Mail configuration. Must be configured to enable user registration confirmation. mail.smtp.socketFactory.port=465 mail.host=localhost mail.user=user diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml index a1484943..b7e6e683 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml @@ -2,6 +2,9 @@ + + + @@ -125,6 +128,7 @@ + @@ -140,7 +144,7 @@ - + settings @@ -326,13 +330,13 @@ - - + class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> + + - + diff --git a/wise-webapp/src/main/webapp/jsp/userRegistrationConfirmation.jsp b/wise-webapp/src/main/webapp/jsp/userRegistrationConfirmation.jsp index fe52bc47..8dcb4af8 100644 --- a/wise-webapp/src/main/webapp/jsp/userRegistrationConfirmation.jsp +++ b/wise-webapp/src/main/webapp/jsp/userRegistrationConfirmation.jsp @@ -6,19 +6,26 @@ -

Thanks for signing up!

-

- You will receive a confirmation message shortly from WiseMapping. This message will ask you to activate your WiseMapping account. - Please select the link to activate and start creating and sharing maps. -

-
-

- Thanks so much for your interest in WiseMapping. -

-
-

- If you have any questions or have any feedback, please don't hesitate to use the on line form. - We'd love to hear from you. -

+

Thanks for signing up!

+ +

+ You will receive a confirmation message shortly from WiseMapping. This message will ask you to activate your WiseMapping account. + Please select the link to activate and start creating and sharing maps. +

+
+

+ Thanks so much for your interest in WiseMapping. +

+
+

+ If you have any questions or have any feedback, please don't hesitate to use the on line form. + We'd love to hear from you. +

+
+ +

+ Your account has been created successfully, click here to sign in and start enjoying WiseMapping. +

+
diff --git a/wise-webapp/src/test/data/freemind/basice.mm b/wise-webapp/src/test/data/freemind/basice.mm index e69de29b..8bf97d1c 100644 --- a/wise-webapp/src/test/data/freemind/basice.mm +++ b/wise-webapp/src/test/data/freemind/basice.mm @@ -0,0 +1 @@ + \ No newline at end of file