Spring Security(Third Edition)
上QQ阅读APP看书,第一时间看更新

Updating SignupController

The application has a SignupController object, which is what processes the HTTP request to create a new CalendarUser object. The last step is to update SignupController to create our user and then indicate that they are logged in. Make the following updates to SignupController:

//src/main/java/com/packtpub/springsecurity/web/controllers/
SignupController.java

@RequestMapping(value="/signup/new", method=RequestMethod.POST)
public String signup(@Valid SignupForm signupForm,
BindingResult result, RedirectAttributes redirectAttributes) {
... existing validation …
user.setPassword(signupForm.getPassword());
int id = calendarService.createUser(user);
user.setId(id);
userContext.setCurrentUser(user);
redirectAttributes.addFlashAttribute("message", "Success");
return "redirect:/";
}

If you have not done so already, restart the application, visit http://localhost:8080/, create a new user, and see that the new user is automatically logged in.

Your code should now look like chapter03.02-calendar.