mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-23 03:43:48 +01:00
Migrate UserRegitration to MVC 3.0.
wisemapping-servlet.xml is not used anymore.
This commit is contained in:
parent
ea2bff60f7
commit
33131d4e9e
@ -42,7 +42,7 @@ public class LoginController {
|
||||
result = new ModelAndView("forward:/c/maps/");
|
||||
} else {
|
||||
result = new ModelAndView("login");
|
||||
result.addObject("isHsql", driver.indexOf("hsql") != -1);
|
||||
result.addObject("isHsql", driver.contains("hsql"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -19,11 +19,19 @@
|
||||
package com.wisemapping.ncontroller;
|
||||
|
||||
|
||||
import com.wisemapping.controller.Messages;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.service.InvalidUserEmailException;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.validator.UserValidator;
|
||||
import com.wisemapping.view.UserBean;
|
||||
import net.tanesha.recaptcha.ReCaptcha;
|
||||
import net.tanesha.recaptcha.ReCaptchaResponse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
@ -32,6 +40,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Properties;
|
||||
|
||||
@Controller
|
||||
public class UsersController {
|
||||
|
||||
@ -39,6 +50,16 @@ public class UsersController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Value("${registration.email.enabled}")
|
||||
boolean emailConfirmEnabled;
|
||||
|
||||
@Autowired
|
||||
private ReCaptcha captchaService;
|
||||
|
||||
@Value("${registration.recaptcha.enabled}")
|
||||
private boolean captchaEnabled;
|
||||
|
||||
|
||||
@RequestMapping(value = "user/resetPassword", method = RequestMethod.GET)
|
||||
public ModelAndView showResetPasswordPage() {
|
||||
return new ModelAndView("forgotPassword");
|
||||
@ -59,7 +80,62 @@ public class UsersController {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setUserService(@NotNull UserService userService) {
|
||||
this.userService = userService;
|
||||
@RequestMapping(value = "user/registration", method = RequestMethod.GET)
|
||||
public ModelAndView showRegistrationPage(@NotNull HttpServletRequest request) {
|
||||
if (captchaEnabled) {
|
||||
// If captcha is enabled, generate it ...
|
||||
final Properties prop = new Properties();
|
||||
prop.put("theme", "white");
|
||||
|
||||
final String captchaHtml = captchaService.createRecaptchaHtml(null, prop);
|
||||
request.setAttribute("captchaHtml", captchaHtml);
|
||||
request.setAttribute("captchaEnabled", true);
|
||||
}
|
||||
return new ModelAndView("userRegistration", "user", new UserBean());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "user/registration", method = RequestMethod.POST)
|
||||
public ModelAndView registerUser(@ModelAttribute("user") UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) throws WiseMappingException {
|
||||
ModelAndView result;
|
||||
validateRegistrationForm(userBean, request, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
result = this.showRegistrationPage(request);
|
||||
result.addObject("user", userBean);
|
||||
} else {
|
||||
final User user = new User();
|
||||
|
||||
// trim() the email email in order to remove spaces ...
|
||||
user.setEmail(userBean.getEmail().trim());
|
||||
user.setUsername(userBean.getUsername());
|
||||
user.setFirstname(userBean.getFirstname());
|
||||
user.setLastname(userBean.getLastname());
|
||||
user.setPassword(userBean.getPassword());
|
||||
userService.createUser(user, emailConfirmEnabled);
|
||||
|
||||
// Forward to the success view ...
|
||||
result = new ModelAndView("userRegistrationSuccess");
|
||||
result.addObject("confirmByEmail", emailConfirmEnabled);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private BindingResult validateRegistrationForm(@NotNull UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) {
|
||||
final UserValidator userValidator = new UserValidator();
|
||||
userValidator.setUserService(userService);
|
||||
userValidator.setCaptchaService(captchaService);
|
||||
userValidator.validate(userBean, bindingResult);
|
||||
|
||||
// If captcha is enabled, generate it ...
|
||||
if (captchaEnabled) {
|
||||
final String challenge = request.getParameter("recaptcha_challenge_field");
|
||||
final String uresponse = request.getParameter("recaptcha_response_field");
|
||||
|
||||
final String remoteAddr = request.getRemoteAddr();
|
||||
final ReCaptchaResponse reCaptchaResponse = captchaService.checkAnswer(remoteAddr, challenge, uresponse);
|
||||
if (!reCaptchaResponse.isValid()) {
|
||||
bindingResult.rejectValue("captcha", Messages.CAPTCHA_ERROR);
|
||||
}
|
||||
}
|
||||
return bindingResult;
|
||||
}
|
||||
}
|
||||
|
@ -22,20 +22,20 @@ import com.wisemapping.model.CollaborationRole;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.User;
|
||||
|
||||
public class ColaboratorBean
|
||||
public class CollaboratorBean
|
||||
{
|
||||
private CollaborationRole collaborationRole;
|
||||
private boolean isUser;
|
||||
private Collaborator collaborator;
|
||||
|
||||
public ColaboratorBean(Collaborator collaborator, CollaborationRole role)
|
||||
public CollaboratorBean(Collaborator collaborator, CollaborationRole role)
|
||||
{
|
||||
this.collaborator = collaborator;
|
||||
this.collaborationRole = role;
|
||||
this.isUser = false;
|
||||
}
|
||||
|
||||
public ColaboratorBean(User user, CollaborationRole role)
|
||||
public CollaboratorBean(User user, CollaborationRole role)
|
||||
{
|
||||
this.collaborator = user;
|
||||
this.collaborationRole = role;
|
@ -29,8 +29,8 @@ import java.util.*;
|
||||
|
||||
public class MindMapBean {
|
||||
private MindMap mindMap;
|
||||
private List<ColaboratorBean> viewers;
|
||||
private List<ColaboratorBean> colaborators;
|
||||
private List<CollaboratorBean> viewers;
|
||||
private List<CollaboratorBean> colaborators;
|
||||
|
||||
public MindMapBean(final MindMap mindmap) {
|
||||
this.mindMap = mindmap;
|
||||
@ -62,11 +62,11 @@ public class MindMapBean {
|
||||
return mindMap.isStarred(Utils.getUser());
|
||||
}
|
||||
|
||||
public List<ColaboratorBean> getViewers() {
|
||||
public List<CollaboratorBean> getViewers() {
|
||||
return viewers;
|
||||
}
|
||||
|
||||
public List<ColaboratorBean> getCollaborators() {
|
||||
public List<CollaboratorBean> getCollaborators() {
|
||||
return colaborators;
|
||||
}
|
||||
|
||||
@ -86,12 +86,12 @@ public class MindMapBean {
|
||||
return mindMap.getTags();
|
||||
}
|
||||
|
||||
private List<ColaboratorBean> getColaboratorBy(Set<Collaboration> source, CollaborationRole role) {
|
||||
List<ColaboratorBean> col = new ArrayList<ColaboratorBean>();
|
||||
private List<CollaboratorBean> getColaboratorBy(Set<Collaboration> source, CollaborationRole role) {
|
||||
List<CollaboratorBean> col = new ArrayList<CollaboratorBean>();
|
||||
if (source != null) {
|
||||
for (Collaboration mu : source) {
|
||||
if (mu.getRole() == role) {
|
||||
col.add(new ColaboratorBean(mu.getCollaborator(), mu.getRole()));
|
||||
col.add(new CollaboratorBean(mu.getCollaborator(), mu.getRole()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,12 +58,12 @@ mail.supportEmail=root@localhost
|
||||
registration.email.enabled = false
|
||||
|
||||
# Enable captcha confirmation
|
||||
registration.recaptcha.enabled = false
|
||||
registration.recaptcha.enabled = true
|
||||
|
||||
# ReCaptcha is the default captcha. Public and private keys are required.
|
||||
# More Info: http://www.google.com/recaptcha
|
||||
registration.recaptcha.privateKey =
|
||||
registration.recaptcha.publicKey =
|
||||
# More Info: http://www.google.com/recaptcha .
|
||||
registration.recaptcha.privateKey = 6LeQ4tISAAAAAMfHMPRKyHupTfA-KE4QeTCnLXhK
|
||||
registration.recaptcha.publicKey = 6LeQ4tISAAAAALzCGKNgRv8UqsDx7Cb0vq4wbJBr
|
||||
|
||||
##################################################################################
|
||||
# Site configuration
|
||||
|
@ -77,9 +77,9 @@
|
||||
<put-attribute name="body" value="/jsp/userRegistration.jsp"/>
|
||||
</definition>
|
||||
|
||||
<definition name="userRegistrationConfirmation" extends="pageTemplate">
|
||||
<definition name="userRegistrationSuccess" extends="pageTemplate">
|
||||
<put-attribute name="title" value="USER_REGISTRATION"/>
|
||||
<put-attribute name="body" value="/jsp/userRegistrationConfirmation.jsp"/>
|
||||
<put-attribute name="body" value="/jsp/userRegistrationSuccess.jsp"/>
|
||||
</definition>
|
||||
|
||||
<definition name="login" extends="pageTemplate">
|
||||
|
@ -74,7 +74,7 @@
|
||||
<value>/index.jsp</value>
|
||||
<value>/c/home</value>
|
||||
<value>/c/login</value>
|
||||
<value>/c/userRegistration</value>
|
||||
<value>/c/user/registration</value>
|
||||
<value>/c/captcha</value>
|
||||
<value>/c/publicView</value>
|
||||
<value>/service/*</value>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<sec:http pattern="/favicon.ico" security="none"/>
|
||||
|
||||
<sec:http pattern="/c/login" security="none"/>
|
||||
<sec:http pattern="/c/userregistration" security="none"/>
|
||||
<sec:http pattern="/c/user/registration" security="none"/>
|
||||
<sec:http pattern="/c/user/resetpassword" security="none"/>
|
||||
<sec:http pattern="/c/home" security="none"/>
|
||||
<sec:http pattern="/c/maps/*/embed" security="none"/>
|
||||
|
@ -3,24 +3,6 @@
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="userValidator" class="com.wisemapping.validator.UserValidator">
|
||||
<property name="userService" ref="userService"/>
|
||||
<property name="captchaService" ref="reCaptcha"/>
|
||||
</bean>
|
||||
|
||||
<bean id="userController" class="com.wisemapping.controller.UserRegistrationController">
|
||||
<property name="sessionForm" value="false"/>
|
||||
<property name="commandName" value="user"/>
|
||||
<property name="commandClass" value="com.wisemapping.view.UserBean"/>
|
||||
<property name="validator" ref="userValidator"/>
|
||||
<property name="formView" value="userRegistration"/>
|
||||
<property name="successView" value="userRegistrationConfirmation"/>
|
||||
<property name="userService" ref="userService"/>
|
||||
<property name="emailConfirmEnabled" value="${registration.email.enabled}"/>
|
||||
<property name="captchaEnabled" value="${registration.recaptcha.enabled}"/>
|
||||
<property name="captchaService" ref="reCaptcha"/>
|
||||
</bean>
|
||||
|
||||
<bean id="settingResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
|
||||
<property name="mappings">
|
||||
<props>
|
||||
@ -61,24 +43,4 @@
|
||||
<bean id="activationController" class="com.wisemapping.controller.ActivationController">
|
||||
<property name="userService" ref="userService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||
<property name="interceptors">
|
||||
<list>
|
||||
<ref bean="browserSupportInterceptor"/>
|
||||
<ref bean="localeChangeInterceptor"/>
|
||||
</list>
|
||||
</property>
|
||||
<property name="mappings">
|
||||
<props>
|
||||
<!-- Forms based -->
|
||||
<prop key="userRegistration">usersController</prop>
|
||||
<prop key="login">loginController</prop>
|
||||
<prop key="activation">activationController</prop>
|
||||
<prop key="changePassword">changePasswordController</prop>
|
||||
<prop key="settings">settingsController</prop>
|
||||
<prop key="editProfile">editProfileController</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
ans>
|
@ -196,7 +196,7 @@ function updateStatusToolbar() {
|
||||
// Can be executed by the owner ?
|
||||
var rowData = tableElem.dataTable().fnGetData(selectedRows[0]);
|
||||
if (rowData.role != 'owner') {
|
||||
$("#buttonsToolbar").find('#publishBtn').hide().end().find('#shareBtn').hide();
|
||||
$("#buttonsToolbar").find('#publishBtn').hide().end().find('#shareBtn').hide().end().find('#renameBtn').hide();
|
||||
}
|
||||
} else {
|
||||
$("#buttonsToolbar .act-multiple").show();
|
||||
|
@ -62,7 +62,7 @@
|
||||
<div id="register">
|
||||
<b><spring:message code="NOT_READY_A_USER"/></b>
|
||||
<spring:message code="NOT_READY_A_USER_MESSAGE"/>
|
||||
<a href="c/userRegistration">
|
||||
<a href="c/user/registration">
|
||||
<spring:message code="JOIN_NOW"/>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -33,7 +33,7 @@
|
||||
<spring:message code="NOT_READY_A_USER"/>
|
||||
</b>
|
||||
<spring:message code="NOT_READY_A_USER_MESSAGE"/>
|
||||
<a href="c/userRegistration">
|
||||
<a href="c/user/registration">
|
||||
<spring:message code="JOIN_NOW"/>
|
||||
</a>
|
||||
</div>
|
@ -1,6 +1,4 @@
|
||||
<%@ include file="/jsp/init.jsp" %>
|
||||
|
||||
|
||||
<div>
|
||||
<div class="fform">
|
||||
|
||||
@ -35,23 +33,28 @@
|
||||
<form:errors path="retypePassword" cssClass="errorMsg"/>
|
||||
|
||||
<c:if test="${requestScope.captchaEnabled}">
|
||||
<form:errors path="captcha" cssClass="errorMsg"/>
|
||||
${requestScope.captchaHtml}
|
||||
<p>
|
||||
<form:errors path="captcha" cssClass="errorMsg"/>
|
||||
</p>
|
||||
</c:if>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
<spring:message code="TERM_OF_THE_SERVICE"/>
|
||||
<spring:message code="WISEMAPPING_ACCOUNT_MESSAGE"/> <a href="c/termsOfUse"><spring:message
|
||||
code="HERE"/></a>
|
||||
code="HERE"/></a>.
|
||||
<spring:message code="REGISTRATION_CLICK_ADVICE"/>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="<spring:message code="REGISTER" />" id="submitButton"
|
||||
<input type="submit" value="<spring:message code="REGISTER"/>"
|
||||
data-loading-text="<spring:message code="REGISTER"/> ..." id="submitButton"
|
||||
class="btn btn-primary">
|
||||
<input type="button" value="<spring:message code="CANCEL"/>"
|
||||
onclick="window.location='c/<c:url value="maps/"/>'" class="btn">
|
||||
</form:form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -1,30 +1,29 @@
|
||||
<%@ include file="/jsp/init.jsp" %>
|
||||
|
||||
<div>
|
||||
<h1>
|
||||
<spring:message code="USER_REGISTRATION"/>
|
||||
</h1>
|
||||
|
||||
|
||||
<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.
|
||||
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}">
|
||||
<c:if test="${confirmByEmail==false}">
|
||||
<p>
|
||||
Your account has been created successfully, click <a href="c/login">here</a> to sign in and start enjoying WiseMapping.
|
||||
Your account has been created successfully, click <a href="c/login">here</a> to sign in and start enjoying
|
||||
WiseMapping.
|
||||
</p>
|
||||
</c:if>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user