content: package net.alanbinu.springboot.loginregistrationspringbootauthjsp.web;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import net.alanbinu.springboot.loginregistrationspringbootauthjsp.model.User;
  import net.alanbinu.springboot.loginregistrationspringbootauthjsp.service.UserService;
  import net.alanbinu.springboot.loginregistrationspringbootauthjsp.validator.UserValidator;
  
  @Controller
  public class UserController {
      @Autowired
      private UserService userService;
  
      @Autowired
      private UserValidator userValidator;
  
      @RequestMapping(value = "/registration", method = RequestMethod.GET)
      public String registration(Model model) {
          model.addAttribute("userForm", new User());
  
          return "registration";
      }
  
      @RequestMapping(value = "/registration", method = RequestMethod.POST)
      public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) {
          userValidator.validate(userForm, bindingResult);
  
          if (bindingResult.hasErrors()) {
              return "registration";
          }
  
          userService.save(userForm);
  
          return "redirect:/welcome";
      }
  
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public String login(Model model, String error, String logout) {
          if (error != null)
              model.addAttribute("error", "Your username and password is invalid.");
  
          if (logout != null)
              model.addAttribute("message", "You have been logged out successfully.");
  
          return "login";
      }
  
      @RequestMapping(value = {"/", "/welcome"}, method = RequestMethod.GET)
      public String welcome(Model model) {
          return "welcome";
      }
  }
  