@RequestMapping(value = "/loginCheck", method = RequestMethod.POST) public String validateUser( Model model, @Valid @ModelAttribute("user") Users user, BindingResult result, HttpSession session) { if (result.hasErrors()) { System.out.println("has errors"); return "login"; } System.out.println("user.getUsername()>>>>" + user.getUsername()); if (user.getUsername() == "admin" || user.getUsername().equals("admin")) { session.setAttribute("user", user); return "redirect:/admin"; } Customer customer = customerService.getCustomerByUsernameAndPassword(user.getUsername(), user.getPassword()); if (customer != null) { session.setAttribute("user", user); return "redirect:/product/productList"; } else { model.addAttribute("logincheckMsg", "Invalid Credentials"); return "login"; } }
@RequestMapping(value = "/register", method = RequestMethod.POST) public String registerCustomerPost( @Valid @ModelAttribute("customer") Customer customer, BindingResult result, Model model) { if (result.hasErrors()) { System.out.println("has errors"); return "registerCustomer"; } System.out.println("has errors postttt"); System.out.println("cutomer>>>" + customer); ArrayList customerList = new ArrayList(); customerList = customerService.getAllCustomers(); if (customerList != null && !customerList.isEmpty()) { for (int i = 0; i < customerList.size(); i++) { if (customer .getCustomerEmail() .equals((String) ((Customer) customerList.get(i)).getCustomerEmail())) { model.addAttribute("emailMsg", "Email already exists"); return "registerCustomer"; } if (customer .getUsername() .equals((String) ((Customer) customerList.get(i)).getUsername())) { model.addAttribute("usernameMsg", "Username already exists"); return "registerCustomer"; } } } customer.setEnabled(true); customerService.addCustomer(customer); return "registerCustomerSuccess"; }