|
32 | 32 | import org.springframework.stereotype.Controller; |
33 | 33 | import org.springframework.ui.Model; |
34 | 34 | import org.springframework.validation.BindingResult; |
35 | | -import org.springframework.web.bind.annotation.ModelAttribute; |
36 | 35 | import org.springframework.web.bind.annotation.RequestMapping; |
37 | 36 | import org.springframework.web.bind.annotation.RequestMethod; |
38 | 37 | import org.springframework.web.bind.annotation.RequestParam; |
39 | 38 | import org.springframework.web.bind.annotation.ResponseBody; |
40 | | -import org.springframework.web.servlet.ModelAndView; |
41 | 39 |
|
42 | 40 | @Controller |
43 | 41 | public class RegistrationController { |
@@ -67,34 +65,21 @@ public RegistrationController() { |
67 | 65 |
|
68 | 66 | // Registration |
69 | 67 |
|
70 | | - @RequestMapping(value = "/user/registration", method = RequestMethod.GET) |
71 | | - public String showRegistrationPage(final Model model) { |
72 | | - LOGGER.debug("Rendering registration page."); |
73 | | - final UserDto accountDto = new UserDto(); |
74 | | - model.addAttribute("user", accountDto); |
75 | | - return "registration"; |
76 | | - } |
77 | | - |
78 | 68 | @RequestMapping(value = "/user/registration", method = RequestMethod.POST) |
79 | | - public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid final UserDto accountDto, final BindingResult result, final HttpServletRequest request) { |
| 69 | + @ResponseBody |
| 70 | + public GenericResponse registerUserAccount(@Valid final UserDto accountDto, final BindingResult result, final HttpServletRequest request) { |
80 | 71 | LOGGER.debug("Registering user account with information: {}", accountDto); |
81 | 72 | if (result.hasErrors()) { |
82 | | - return new ModelAndView("registration", "user", accountDto); |
| 73 | + return new GenericResponse(result.getFieldErrors(), result.getGlobalErrors()); |
83 | 74 | } |
84 | | - |
85 | 75 | final User registered = createUserAccount(accountDto); |
86 | 76 | if (registered == null) { |
87 | | - result.rejectValue("email", "message.regError"); |
88 | | - return new ModelAndView("registration", "user", accountDto); |
| 77 | + return new GenericResponse("email", messages.getMessage("message.regError", null, request.getLocale())); |
89 | 78 | } |
90 | | - try { |
91 | | - final String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); |
92 | | - eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl)); |
93 | | - } catch (final Exception ex) { |
94 | | - LOGGER.warn("Unable to register user", ex); |
95 | | - return new ModelAndView("emailError", "user", accountDto); |
96 | | - } |
97 | | - return new ModelAndView("successRegister", "user", accountDto); |
| 79 | + final String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); |
| 80 | + eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered, request.getLocale(), appUrl)); |
| 81 | + |
| 82 | + return new GenericResponse("success"); |
98 | 83 | } |
99 | 84 |
|
100 | 85 | @RequestMapping(value = "/regitrationConfirm", method = RequestMethod.GET) |
|
0 commit comments