mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Add configurable email confirmation.
This commit is contained in:
parent
7fdf08a6b1
commit
2021a39229
@ -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) {
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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");
|
||||||
@ -67,7 +66,7 @@ public class UserServiceImpl
|
|||||||
changePassword(user);
|
changePassword(user);
|
||||||
model.put("user", user);
|
model.put("user", user);
|
||||||
model.put("password", password);
|
model.put("password", password);
|
||||||
|
|
||||||
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "WiseMapping : Recovery Password", model, "recoveryMail.vm");
|
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "WiseMapping : Recovery Password", model, "recoveryMail.vm");
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidUserEmailException("The email '" + email + "' does not exists.");
|
throw new InvalidUserEmailException("The email '" + email + "' does not exists.");
|
||||||
@ -91,30 +90,41 @@ 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);
|
||||||
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
mailer.sendEmail(mailer.getRegistrationEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
||||||
"confirmationMail.vm");
|
"confirmationMail.vm");
|
||||||
|
@ -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
|
||||||
|
@ -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"/>
|
||||||
@ -140,7 +144,7 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="settingResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
|
<bean id="settingResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
|
||||||
<property name="mappings">
|
<property name="mappings">
|
||||||
<props>
|
<props>
|
||||||
<prop key="/c/settings.htm">settings</prop>
|
<prop key="/c/settings.htm">settings</prop>
|
||||||
</props>
|
</props>
|
||||||
@ -326,13 +330,13 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="localeResolver"
|
<bean id="localeResolver"
|
||||||
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
|
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
|
||||||
<property name="defaultLocale" value="en" />
|
<property name="defaultLocale" value="en"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="localeChangeInterceptor"
|
<bean id="localeChangeInterceptor"
|
||||||
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
|
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
|
||||||
<property name="paramName" value="language" />
|
<property name="paramName" value="language"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,19 +6,26 @@
|
|||||||
<spring:message code="USER_REGISTRATION"/>
|
<spring:message code="USER_REGISTRATION"/>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
|
|
||||||
|
|
||||||
<p>
|
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
|
||||||
You will receive a confirmation message shortly from WiseMapping. This message will ask you to activate your WiseMapping account.
|
<c:if test="${confirmByEmail==true}">
|
||||||
Please select the link to activate and start creating and sharing maps.
|
<p>
|
||||||
</p>
|
You will receive a confirmation message shortly from WiseMapping. This message will ask you to activate your WiseMapping account.
|
||||||
<br/>
|
Please select the link to activate and start creating and sharing maps.
|
||||||
<p>
|
</p>
|
||||||
Thanks so much for your interest in WiseMapping.
|
<br/>
|
||||||
</p>
|
<p>
|
||||||
<br/>
|
Thanks so much for your interest in WiseMapping.
|
||||||
<p>
|
</p>
|
||||||
If you have any questions or have any feedback, please don't hesitate to use the on line form.
|
<br/>
|
||||||
We'd love to hear from you.
|
<p>
|
||||||
</p>
|
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.
|
||||||
|
</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>
|
||||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user