3232import org .springframework .stereotype .Controller ;
3333import org .springframework .ui .Model ;
3434import org .springframework .validation .BindingResult ;
35- import org .springframework .validation .Errors ;
3635import org .springframework .web .bind .annotation .ModelAttribute ;
3736import org .springframework .web .bind .annotation .RequestMapping ;
3837import org .springframework .web .bind .annotation .RequestMethod ;
@@ -66,20 +65,40 @@ public RegistrationController() {
6665
6766 }
6867
69- // API
68+ // Registration
7069
7170 @ RequestMapping (value = "/user/registration" , method = RequestMethod .GET )
72- public String showRegistrationForm ( final HttpServletRequest request , final Model model ) {
71+ public String showRegistrationPage ( final Model model ) {
7372 LOGGER .debug ("Rendering registration page." );
7473 final UserDto accountDto = new UserDto ();
7574 model .addAttribute ("user" , accountDto );
7675 return "registration" ;
7776 }
7877
79- @ RequestMapping (value = "/regitrationConfirm" , method = RequestMethod .GET )
80- public String confirmRegistration (final HttpServletRequest request , final Model model , @ RequestParam ("token" ) final String token ) {
81- final Locale locale = request .getLocale ();
78+ @ RequestMapping (value = "/user/registration" , method = RequestMethod .POST )
79+ public ModelAndView registerUserAccount (@ ModelAttribute ("user" ) @ Valid final UserDto accountDto , final BindingResult result , final HttpServletRequest request ) {
80+ LOGGER .debug ("Registering user account with information: {}" , accountDto );
81+ if (result .hasErrors ()) {
82+ return new ModelAndView ("registration" , "user" , accountDto );
83+ }
84+
85+ final User registered = createUserAccount (accountDto );
86+ if (registered == null ) {
87+ result .rejectValue ("email" , "message.regError" );
88+ return new ModelAndView ("registration" , "user" , accountDto );
89+ }
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 );
98+ }
8299
100+ @ RequestMapping (value = "/regitrationConfirm" , method = RequestMethod .GET )
101+ public String confirmRegistration (final Locale locale , final Model model , @ RequestParam ("token" ) final String token ) {
83102 final VerificationToken verificationToken = userService .getVerificationToken (token );
84103 if (verificationToken == null ) {
85104 final String message = messages .getMessage ("auth.message.invalidToken" , null , locale );
@@ -102,27 +121,7 @@ public String confirmRegistration(final HttpServletRequest request, final Model
102121 return "redirect:/login.html?lang=" + locale .getLanguage ();
103122 }
104123
105- @ RequestMapping (value = "/user/registration" , method = RequestMethod .POST )
106- public ModelAndView registerUserAccount (@ ModelAttribute ("user" ) @ Valid final UserDto accountDto , final BindingResult result , final HttpServletRequest request , final Errors errors ) {
107- LOGGER .debug ("Registering user account with information: {}" , accountDto );
108- if (result .hasErrors ()) {
109- return new ModelAndView ("registration" , "user" , accountDto );
110- }
111-
112- final User registered = createUserAccount (accountDto );
113- if (registered == null ) {
114- result .rejectValue ("email" , "message.regError" );
115- return new ModelAndView ("registration" , "user" , accountDto );
116- }
117- try {
118- final String appUrl = "http://" + request .getServerName () + ":" + request .getServerPort () + request .getContextPath ();
119- eventPublisher .publishEvent (new OnRegistrationCompleteEvent (registered , request .getLocale (), appUrl ));
120- } catch (final Exception ex ) {
121- LOGGER .warn ("Unable to register user" , ex );
122- return new ModelAndView ("emailError" , "user" , accountDto );
123- }
124- return new ModelAndView ("successRegister" , "user" , accountDto );
125- }
124+ // user activation - verification
126125
127126 @ RequestMapping (value = "/user/resendRegistrationToken" , method = RequestMethod .GET )
128127 @ ResponseBody
@@ -156,9 +155,7 @@ public GenericResponse resetPassword(final HttpServletRequest request, @RequestP
156155 }
157156
158157 @ RequestMapping (value = "/user/changePassword" , method = RequestMethod .GET )
159- public String showChangePasswordPage (final HttpServletRequest request , final Model model , @ RequestParam ("id" ) final long id , @ RequestParam ("token" ) final String token ) {
160- final Locale locale = request .getLocale ();
161-
158+ public String showChangePasswordPage (final Locale locale , final Model model , @ RequestParam ("id" ) final long id , @ RequestParam ("token" ) final String token ) {
162159 final PasswordResetToken passToken = userService .getPasswordResetToken (token );
163160 final User user = passToken .getUser ();
164161 if (passToken == null || user .getId () != id ) {
@@ -182,10 +179,10 @@ public String showChangePasswordPage(final HttpServletRequest request, final Mod
182179 @ RequestMapping (value = "/user/savePassword" , method = RequestMethod .POST )
183180 @ PreAuthorize ("hasRole('READ_PRIVILEGE')" )
184181 @ ResponseBody
185- public GenericResponse savePassword (final HttpServletRequest request , @ RequestParam ("password" ) final String password ) {
182+ public GenericResponse savePassword (final Locale locale , @ RequestParam ("password" ) final String password ) {
186183 final User user = (User ) SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ();
187184 userService .changeUserPassword (user , password );
188- return new GenericResponse (messages .getMessage ("message.resetPasswordSuc" , null , request . getLocale () ));
185+ return new GenericResponse (messages .getMessage ("message.resetPasswordSuc" , null , locale ));
189186 }
190187
191188 // NON-API
0 commit comments