Add configurable email confirmation.

This commit is contained in:
Paulo Gustavo Veiga 2011-03-12 19:10:44 -03:00
parent 7fdf08a6b1
commit 2021a39229
7 changed files with 77 additions and 36 deletions

View File

@ -33,15 +33,28 @@ import com.wisemapping.view.UserBean;
import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.exceptions.WiseMappingException;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.Map;
public class UserController public class UserController
extends CaptchaFormController { extends CaptchaFormController {
//~ Instance fields ...................................................................................... //~ Instance fields ......................................................................................
private boolean emailConfirmEnabled;
private UserService userService; private UserService userService;
//~ Methods .............................................................................................. //~ Methods ..............................................................................................
public boolean isEmailConfirmEnabled() {
return emailConfirmEnabled;
}
public void setEmailConfirmEnabled(boolean emailConfirmEnabled) {
this.emailConfirmEnabled = emailConfirmEnabled;
}
public ModelAndView onSubmit(Object command) throws WiseMappingException { public ModelAndView onSubmit(Object command) throws WiseMappingException {
final UserBean userBean = ((UserBean) command); final UserBean userBean = ((UserBean) command);
@ -53,10 +66,12 @@ public class UserController
user.setFirstname(userBean.getFirstname()); user.setFirstname(userBean.getFirstname());
user.setLastname(userBean.getLastname()); user.setLastname(userBean.getLastname());
user.setPassword(userBean.getPassword()); user.setPassword(userBean.getPassword());
userService.createUser(user); userService.createUser(user,emailConfirmEnabled);
} }
return new ModelAndView(getSuccessView()); final Map<String,Object> model = new HashMap<String,Object>();
model.put("confirmByEmail",emailConfirmEnabled);
return new ModelAndView(getSuccessView(),model);
} }
public void setUserService(UserService userService) { public void setUserService(UserService userService) {

View File

@ -25,7 +25,7 @@ public interface UserService {
public void activateAcount(long code) throws InvalidActivationCodeException; 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); public void changePassword(User user);

View File

@ -38,8 +38,7 @@ public class UserServiceImpl
final static Logger logger = Logger.getLogger("org.wisemapping.service"); final static Logger logger = Logger.getLogger("org.wisemapping.service");
public void activateAcount(long code) public void activateAcount(long code)
throws InvalidActivationCodeException throws InvalidActivationCodeException {
{
final User user = userManager.getUserByActivationCode(code); final User user = userManager.getUserByActivationCode(code);
if (user == null || user.isActive()) { if (user == null || user.isActive()) {
throw new InvalidActivationCodeException("Invalid Activation Code"); throw new InvalidActivationCodeException("Invalid Activation Code");
@ -91,28 +90,39 @@ public class UserServiceImpl
return lo + i; return lo + i;
} }
public void createUser(User user) throws WiseMappingException { public void createUser(User user, boolean emailConfirmEnabled) throws WiseMappingException {
final UUID uuid = UUID.randomUUID(); final UUID uuid = UUID.randomUUID();
user.setCreationDate(Calendar.getInstance()); user.setCreationDate(Calendar.getInstance());
user.setActivationDate(null);
user.setActivationCode(uuid.getLeastSignificantBits()); user.setActivationCode(uuid.getLeastSignificantBits());
Colaborator col = userManager.getColaboratorBy(user.getEmail()); if (emailConfirmEnabled) {
if (col != null) user.setActivationDate(null);
{
userManager.createUser(user,col); } else {
user.setActivationDate(Calendar.getInstance());
} }
else
{ Colaborator col = userManager.getColaboratorBy(user.getEmail());
if (col != null) {
userManager.createUser(user, col);
} else {
userManager.createUser(user); userManager.createUser(user);
} }
//create welcome map //create welcome map
mindmapService.addWelcomeMindmap(user); mindmapService.addWelcomeMindmap(user);
// Send registration email.
if (emailConfirmEnabled) {
sendRegistrationEmail(user);
}
}
private void sendRegistrationEmail(User user) {
final Map<String, Object> model = new HashMap<String, Object>(); final Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user); model.put("user", user);
// TODO: ver como no hacer hardcode el url
final String activationUrl = "http://wisemapping.com/c/activation.htm?code=" + user.getActivationCode(); 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); model.put("emailcheck", activationUrl);

View File

@ -13,7 +13,11 @@ database.hibernate.dialect=org.hibernate.dialect.HSQLDialect
database.username=sa database.username=sa
database.password= 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.smtp.socketFactory.port=465
mail.host=localhost mail.host=localhost
mail.user=user mail.user=user

View File

@ -2,6 +2,9 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans> <beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties"/>
</bean>
<bean id="browserSupportInterceptor" class="com.wisemapping.filter.BrowserSupportInterceptor"> <bean id="browserSupportInterceptor" class="com.wisemapping.filter.BrowserSupportInterceptor">
<property name="exclude"> <property name="exclude">
@ -125,6 +128,7 @@
<property name="formView" value="userRegistration"/> <property name="formView" value="userRegistration"/>
<property name="successView" value="userRegistrationConfirmation"/> <property name="successView" value="userRegistrationConfirmation"/>
<property name="userService" ref="userService"/> <property name="userService" ref="userService"/>
<property name="emailConfirmEnabled" value="${user.confirm.registration}"/>
</bean> </bean>
<bean id="forgotPasswordValidator" class="com.wisemapping.validator.ForgotPasswordValidator"/> <bean id="forgotPasswordValidator" class="com.wisemapping.validator.ForgotPasswordValidator"/>

View File

@ -6,8 +6,9 @@
<spring:message code="USER_REGISTRATION"/> <spring:message code="USER_REGISTRATION"/>
</h1> </h1>
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
<c:if test="${confirmByEmail==true}">
<p> <p>
You will receive a confirmation message shortly from WiseMapping. This message will ask you to activate your WiseMapping account. 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. Please select the link to activate and start creating and sharing maps.
@ -21,4 +22,10 @@
If you have any questions or have any feedback, please don't hesitate to use the on line form. 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. We'd love to hear from you.
</p> </p>
</c:if>
<c:if test="${confirmByEmail==false}">
<p>
Your account has been created successfully, click <a href="login.htm">here</a> to sign in and start enjoying WiseMapping.
</p>
</c:if>
</div> </div>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><map version="0.9.0"><node TEXT="This is the root node" STYLE="elipse" ID="ID_0"><node TEXT="Child Level 1 Right 1" ID="ID_1"/><node TEXT="Child Level 1 Left 1" ID="ID_2"><node TEXT="Child Level 2 Left 11" ID="ID_3"/><node TEXT="Child Level 2 Left 12" ID="ID_4"/></node><node TEXT="Child Level 1 Right 2" ID="ID_5"/><node TEXT="Child Level 1 Left 2" ID="ID_6"><node TEXT="Child Level 2 Left 21 " ID="ID_7"/><node TEXT="Child Level 2 Left 22" ID="ID_8"/></node></node></map>