Database Reference
In-Depth Information
Listing 11-23.
login
Controller
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView
addUser
(@ModelAttribute("graphStory") GraphStory graphStory, HttpServletResponse
response) {
ModelAndView modelAndView;
try {
graphStory =
graphStoryInterface.getUserInterface().login
(graphStory);
// no errors, user was found
if (CollectionUtils.isEmpty(graphStory.getErrorMsgs())) {
response.addCookie
(graphStoryInterface.getHelperInterface().
addCookie(GraphStoryConstants.graphstoryUserAuthKey, graphStory.getUser().
getUsername()));
modelAndView = new ModelAndView("redirect:/social");
// user was not found
} else {
modelAndView = new ModelAndView("/mustache/html/home/message.html");
modelAndView.addObject("title", "Tell Yours");
modelAndView.addObject(graphStory.getErrorMsgs());
}
return modelAndView;
}
catch (Exception e) {
log.error(e);
return null;
}
}
Login Service
To check to see if the user attempting to log in is a valid user, the application uses the
login
method in
UserImpl
,
which implements in
UserInterface
. An abbreviated version of
UserInterface
is shown in Listing 11-24.
Listing 11-24.
UserInterface
with the
login
Method
public interface
UserInterface
{
...
public GraphStory
login
(GraphStory graphStory) throws Exception;
...
}