I am making a small project in Spring MVC. My login controller looks like this:
@Controller
public class LoginController
{
@Autowired
private Environment env;
private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
private AuthenticationService authenticationService = AuthenticationService.getAuthenticationInstance();
@RequestMapping(value = "/login.jsp" , method = RequestMethod.GET)
public ModelAndView userLoginPage(){
return new ModelAndView("Login");
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView userLogin(@ModelAttribute LoginModel loginModel) {
LOGGER.info("Employee trying to login [{}] ", loginModel.toString());
ModelAndView loginView = new ModelAndView();
loginView.addObject("loginModel", loginModel);
String login = authenticationService.authenticateUser(loginModel,env);
switch (login) {
case "Authenticated":
loginView.setViewName("dashboard");
break;
case "Authenticated First time Login":
loginView.setViewName("changepassword");
break;
case "Not Authenticated":
loginView.setViewName("Login");
loginView.addObject("invalid", "invalid user/password");
break;
}
return loginView;
}
@RequestMapping(value = "/changePassword" , method = RequestMethod.POST)
public ModelAndView userPasswordChange(@ModelAttribute
PasswordChangeModel passwordChangeModel){
LOGGER.info("Employee trying to change password [{}]
",passwordChangeModel.getUserid());
authenticationService.changePassword(passwordChangeModel, env);
return new ModelAndView("passwordchangesuccess");
}
}
I am using switch
case to delegate to different views. Is this the right approach or should I do something else to delegate response to views?