private bool ValidateUserNamePasswordLogin(LoginModel login, string redirectUrl, out ActionResult redirect)
 {
     try
     {
         if (authProvider.Authenticate(login.Name, login.UserName, login.Password))
         {
             redirect = Redirect(redirectUrl);
             return true;
         }
     }
     catch (InvalidCredentialsException)
     {
         ModelState.AddModelError("", "Invalid user name or password");
         RedirectToAction("Fail");
     }
     catch (UserNotAuthenticatedException)
     {
         ModelState.AddModelError("", "User could not be identified");
         RedirectToAction("Fail");
     }
     catch (UnsupportedAuthenticationType)
     {
         ModelState.AddModelError("", "Authentication mode not supported");
         RedirectToAction("Fail");
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Something went wrong");
         redirect = View();
         return true;
     }
     redirect = View();
     return false;
 }
 public ActionResult Index(UserInfo userInfo, LoginModel login, string returnUrl)
 {
     string redirectUrl = returnUrl ?? Url.Action("Index", "Home");
     ActionResult redirect;
     if (ValidateUserNamePasswordLogin(login, redirectUrl, out redirect))
     {
         userInfo.Name = login.Name;
         userInfo.UserName = login.UserName;
         return redirect;
     }
     return RedirectToAction("Fail");
 }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
 public ActionResult LogOut(LoginModel login)
 {
     authProvider.SignOut(HttpContext);
     return RedirectToAction("Index", "Home");
 }
 public ActionResult Fail(LoginModel login)
 {
     return View();
 }