@ModelAttribute(Key.loginUserForm) UserRO userRO) {
try {
// Authenticate the credentials
if ((userRO.username != null && userRO.username.trim().length() > 0)
&& (userRO.password != null && userRO.password.trim().length() > 0)) {
final User user = userService.findByUsername(userRO.username);
log.info("User Found: " + user.getUserName());
if (user.getPassWord().equals(User.hashPassword(userRO.password))) {
log.info("Authenticated: " + user.getUserName());
// Update the login count and other info
userService.loginUser(user, request);
// Store the user in session
request.getSession(true).setAttribute(Key.userInSession, user);
model.addAttribute("ls", true);
return Key.redirect + Route.dashboard;
} else {
log.info("User Authentication Failed: " + user.getUserName());
throw new AuthenticationFailedException(msg.aFailed, msg.aFailedCode);
}
} else {
throw new AuthCredentialsMissingException(msg.aParamMissing, msg.aParamMissingCode);
}