Add configurable email confirmation.
This commit is contained in:
@@ -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");
|
||||
|
Reference in New Issue
Block a user