Spring MVC checking user password
I am Trying to check the user is already registered or not as well as the password is correct or not but i am getting error as i mentioned down here is the both controller ->
The errror :
@GetMapping("/login")
public String loginPage(Model model) {
model.addAttribute("movieFinderLoginUserPojo", new MovieFinderLoginUserPojo());
return "login";
}
@PostMapping("/loggedIn")
public String loggedInUser( @Valid @ModelAttribute("MovieFinderLoginUserPojo") MovieFinderLoginUserPojo movieFinderLoginUserPojo , BindingResult bindingResult , HttpSession httpSession , Model model) {
if(bindingResult.hasErrors())
{
System.out.println(bindingResult.getErrorCount());
return "login";
}
try {
String email = movieFinderLoginUserPojo.getEmail();
MovieFinderUser existingUser = finderUserImp.findByEmail(email);
if(existingUser!=null && existingUser.getPassword().equals(movieFinderLoginUserPojo.getPassword())){
httpSession.setAttribute("isLoggedIn", true);
System.out.println("The Email and Password is Correct ");
return "redirect:/home"; // Redirecting to the home page
}
else {
model.addAttribute("error", "Invalid email or password.");
return "login";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
return "login";
}
}
@GetMapping("/login")
public String loginPage(Model model) {
model.addAttribute("movieFinderLoginUserPojo", new MovieFinderLoginUserPojo());
return "login";
}
@PostMapping("/loggedIn")
public String loggedInUser( @Valid @ModelAttribute("MovieFinderLoginUserPojo") MovieFinderLoginUserPojo movieFinderLoginUserPojo , BindingResult bindingResult , HttpSession httpSession , Model model) {
if(bindingResult.hasErrors())
{
System.out.println(bindingResult.getErrorCount());
return "login";
}
try {
String email = movieFinderLoginUserPojo.getEmail();
MovieFinderUser existingUser = finderUserImp.findByEmail(email);
if(existingUser!=null && existingUser.getPassword().equals(movieFinderLoginUserPojo.getPassword())){
httpSession.setAttribute("isLoggedIn", true);
System.out.println("The Email and Password is Correct ");
return "redirect:/home"; // Redirecting to the home page
}
else {
model.addAttribute("error", "Invalid email or password.");
return "login";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
return "login";
}
}
The errror :
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'movieFinderLoginUserPojo' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153)Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'movieFinderLoginUserPojo' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153)