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