I wrote login system on spring-boot but there is a problem when I want to login, spring take login and password from form but cannot redirect to the account page.
@PostMapping(value = "user/login")
public String login(Model model, HttpSession session, @RequestParam("login") String login, @RequestParam("password") String password) {
try {
User user = userService.checkLogin(login, password);
if (user == null) {
model.addAttribute("err", "Login Valid login and password");
return "/login";
} else {
if (user.getRole().equals(userService.Role_Admin)) {
userService.addUserInSession(user, session);
return "/admin/account";
} else if (user.getRole().equals(userService.Role_Student)) {
userService.addUserInSession(user, session);
return "/student/account";
} else {
model.addAttribute("err", "Invalid User Role");
return "/login";
}
} } catch (UserException ex) {
model.addAttribute("err", ex.getMessage());
return "/login";
}
}
Aucun commentaire:
Enregistrer un commentaire