Ejemplo n.º 1
0
 public ActionResult Login(LoginViewModel loginViewModel)
 {
     var user = Session["logged_user"] as User;
     if (user != null)
     {
         return HandleRedirectionBasedOnUserRole(user);
     }
     try
     {
         var loggedUser = authenticationService.Authenticate(loginViewModel.UserName, loginViewModel.Password, loginViewModel.BranchName);
         if (!loggedUser.IsActive)
         {
             return HandleUserLoginError(loginViewModel, "Username is deactivated");
         }
         authenticationService.SetAuthCookie(loginViewModel.UserName);
         Session["logged_user"] = loggedUser;
         return HandleRedirectionBasedOnUserRole(loggedUser);
     }
     catch (ArgumentException exception)
     {
         return HandleUserLoginError(loginViewModel, exception.Message);
     }
 }
Ejemplo n.º 2
0
 private ActionResult HandleUserLoginError(LoginViewModel loginViewModel, string modelErrorMessage)
 {
     PutBranchesInViewBag();
     ModelState.AddModelError("UserName", modelErrorMessage);
     return View(loginViewModel);
 }