mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-22 19:33:48 +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 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<String,Object> model = new HashMap<String,Object>();
|
||||
model.put("confirmByEmail",emailConfirmEnabled);
|
||||
return new ModelAndView(getSuccessView(),model);
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<String, Object> model = new HashMap<String, Object>();
|
||||
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");
|
||||
|
@ -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
|
||||
|
@ -2,6 +2,9 @@
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<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">
|
||||
<property name="exclude">
|
||||
@ -125,6 +128,7 @@
|
||||
<property name="formView" value="userRegistration"/>
|
||||
<property name="successView" value="userRegistrationConfirmation"/>
|
||||
<property name="userService" ref="userService"/>
|
||||
<property name="emailConfirmEnabled" value="${user.confirm.registration}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="forgotPasswordValidator" class="com.wisemapping.validator.ForgotPasswordValidator"/>
|
||||
@ -140,7 +144,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="settingResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
|
||||
<property name="mappings">
|
||||
<property name="mappings">
|
||||
<props>
|
||||
<prop key="/c/settings.htm">settings</prop>
|
||||
</props>
|
||||
@ -326,13 +330,13 @@
|
||||
</bean>
|
||||
|
||||
<bean id="localeResolver"
|
||||
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
|
||||
<property name="defaultLocale" value="en" />
|
||||
</bean>
|
||||
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
|
||||
<property name="defaultLocale" value="en"/>
|
||||
</bean>
|
||||
|
||||
<bean id="localeChangeInterceptor"
|
||||
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
|
||||
<property name="paramName" value="language" />
|
||||
<property name="paramName" value="language"/>
|
||||
</bean>
|
||||
|
||||
|
||||
|
@ -6,19 +6,26 @@
|
||||
<spring:message code="USER_REGISTRATION"/>
|
||||
</h1>
|
||||
|
||||
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
|
||||
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<br/>
|
||||
<p>
|
||||
Thanks so much for your interest in WiseMapping.
|
||||
</p>
|
||||
<br/>
|
||||
<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>
|
||||
<h2 style="font-weight:bold;">Thanks for signing up!</h2>
|
||||
<c:if test="${confirmByEmail==true}">
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<br/>
|
||||
<p>
|
||||
Thanks so much for your interest in WiseMapping.
|
||||
</p>
|
||||
<br/>
|
||||
<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>
|
||||
|
@ -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