cleanup work
This commit is contained in:
parent
ea3c108c31
commit
4acb3eee83
|
@ -46,7 +46,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
|
|||
registry.addViewController("/invalidSession.html");
|
||||
registry.addViewController("/console.html");
|
||||
registry.addViewController("/admin.html");
|
||||
registry.addViewController("/registration.html");
|
||||
registry.addViewController("/successRegister.html");
|
||||
registry.addViewController("/forgetPassword.html");
|
||||
registry.addViewController("/updatePassword.html");
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -66,20 +65,40 @@ public class RegistrationController {
|
|||
|
||||
}
|
||||
|
||||
// API
|
||||
// Registration
|
||||
|
||||
@RequestMapping(value = "/user/registration", method = RequestMethod.GET)
|
||||
public String showRegistrationForm(final HttpServletRequest request, final Model model) {
|
||||
public String showRegistrationPage(final Model model) {
|
||||
LOGGER.debug("Rendering registration page.");
|
||||
final UserDto accountDto = new UserDto();
|
||||
model.addAttribute("user", accountDto);
|
||||
return "registration";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/regitrationConfirm", method = RequestMethod.GET)
|
||||
public String confirmRegistration(final HttpServletRequest request, final Model model, @RequestParam("token") final String token) {
|
||||
final Locale locale = request.getLocale();
|
||||
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
|
||||
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid final UserDto accountDto, final BindingResult result, final HttpServletRequest request) {
|
||||
LOGGER.debug("Registering user account with information: {}", accountDto);
|
||||
if (result.hasErrors()) {
|
||||
return new ModelAndView("registration", "user", accountDto);
|
||||
}
|
||||
|
||||
final User registered = createUserAccount(accountDto);
|
||||
if (registered == null) {
|
||||
result.rejectValue("email", "message.regError");
|
||||
return new ModelAndView("registration", "user", accountDto);
|
||||
}
|
||||
try {
|
||||
final String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
|
||||
eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl));
|
||||
} catch (final Exception ex) {
|
||||
LOGGER.warn("Unable to register user", ex);
|
||||
return new ModelAndView("emailError", "user", accountDto);
|
||||
}
|
||||
return new ModelAndView("successRegister", "user", accountDto);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/regitrationConfirm", method = RequestMethod.GET)
|
||||
public String confirmRegistration(final Locale locale, final Model model, @RequestParam("token") final String token) {
|
||||
final VerificationToken verificationToken = userService.getVerificationToken(token);
|
||||
if (verificationToken == null) {
|
||||
final String message = messages.getMessage("auth.message.invalidToken", null, locale);
|
||||
|
@ -102,27 +121,7 @@ public class RegistrationController {
|
|||
return "redirect:/login.html?lang=" + locale.getLanguage();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
|
||||
public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid final UserDto accountDto, final BindingResult result, final HttpServletRequest request, final Errors errors) {
|
||||
LOGGER.debug("Registering user account with information: {}", accountDto);
|
||||
if (result.hasErrors()) {
|
||||
return new ModelAndView("registration", "user", accountDto);
|
||||
}
|
||||
|
||||
final User registered = createUserAccount(accountDto);
|
||||
if (registered == null) {
|
||||
result.rejectValue("email", "message.regError");
|
||||
return new ModelAndView("registration", "user", accountDto);
|
||||
}
|
||||
try {
|
||||
final String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
|
||||
eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl));
|
||||
} catch (final Exception ex) {
|
||||
LOGGER.warn("Unable to register user", ex);
|
||||
return new ModelAndView("emailError", "user", accountDto);
|
||||
}
|
||||
return new ModelAndView("successRegister", "user", accountDto);
|
||||
}
|
||||
// user activation - verification
|
||||
|
||||
@RequestMapping(value = "/user/resendRegistrationToken", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
|
@ -156,9 +155,7 @@ public class RegistrationController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/user/changePassword", method = RequestMethod.GET)
|
||||
public String showChangePasswordPage(final HttpServletRequest request, final Model model, @RequestParam("id") final long id, @RequestParam("token") final String token) {
|
||||
final Locale locale = request.getLocale();
|
||||
|
||||
public String showChangePasswordPage(final Locale locale, final Model model, @RequestParam("id") final long id, @RequestParam("token") final String token) {
|
||||
final PasswordResetToken passToken = userService.getPasswordResetToken(token);
|
||||
final User user = passToken.getUser();
|
||||
if (passToken == null || user.getId() != id) {
|
||||
|
@ -182,10 +179,10 @@ public class RegistrationController {
|
|||
@RequestMapping(value = "/user/savePassword", method = RequestMethod.POST)
|
||||
@PreAuthorize("hasRole('READ_PRIVILEGE')")
|
||||
@ResponseBody
|
||||
public GenericResponse savePassword(final HttpServletRequest request, @RequestParam("password") final String password) {
|
||||
public GenericResponse savePassword(final Locale locale, @RequestParam("password") final String password) {
|
||||
final User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
userService.changeUserPassword(user, password);
|
||||
return new GenericResponse(messages.getMessage("message.resetPasswordSuc", null, request.getLocale()));
|
||||
return new GenericResponse(messages.getMessage("message.resetPasswordSuc", null, locale));
|
||||
}
|
||||
|
||||
// NON-API
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="sec"
|
||||
uri="http://www.springframework.org/security/tags"%>
|
||||
<%@ page session="false"%>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -15,48 +13,41 @@
|
|||
<body>
|
||||
<div class="container">
|
||||
<div class="span12">
|
||||
<H1>
|
||||
<h1>
|
||||
<spring:message code="label.form.title"></spring:message>
|
||||
</H1>
|
||||
</h1>
|
||||
<form:form modelAttribute="user" method="POST" enctype="utf8">
|
||||
<br>
|
||||
<tr>
|
||||
<td><label><spring:message code="label.user.firstName"></spring:message></label></td>
|
||||
<td><form:input path="firstName" value="" /></td>
|
||||
<form:errors path="firstName" cssClass="alert alert-error"
|
||||
element="div" />
|
||||
<form:errors path="firstName" cssClass="alert alert-error" element="div" />
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><spring:message code="label.user.lastName"></spring:message></label></td>
|
||||
<td><form:input path="lastName" value="" /></td>
|
||||
<form:errors path="lastName" cssClass="alert alert-error"
|
||||
element="div" />
|
||||
<form:errors path="lastName" cssClass="alert alert-error" element="div" />
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><spring:message code="label.user.email"></spring:message></label></td>
|
||||
<td><form:input path="email" value="" /></td>
|
||||
<form:errors path="email" cssClass="alert alert-error"
|
||||
element="div" />
|
||||
<form:errors path="email" cssClass="alert alert-error" element="div" />
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><spring:message code="label.user.password"></spring:message></label></td>
|
||||
<td><form:input path="password" value="" type="password" /></td>
|
||||
<form:errors path="password" cssClass="alert alert-error"
|
||||
element="div" />
|
||||
<form:errors path="password" cssClass="alert alert-error" element="div" />
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><spring:message
|
||||
code="label.user.confirmPass"></spring:message></label></td>
|
||||
<td><form:input path="matchingPassword" value=""
|
||||
type="password" /></td>
|
||||
<td><label><spring:message code="label.user.confirmPass"></spring:message></label></td>
|
||||
<td><form:input path="matchingPassword" value="" type="password" /></td>
|
||||
<form:errors cssClass="alert alert-error" element="div" />
|
||||
</tr>
|
||||
<button type="submit">
|
||||
<spring:message code="label.form.submit"></spring:message>
|
||||
</button>
|
||||
</form:form>
|
||||
<br> <a href="<c:url value="login.html" />"><spring:message
|
||||
code="label.form.loginLink"></spring:message></a>
|
||||
<br> <a href="<c:url value="login.html" />"><spring:message code="label.form.loginLink"></spring:message></a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue