Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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");
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public ActionResult LogOut(LoginModel login)
 {
     authProvider.SignOut(HttpContext);
     return RedirectToAction("Index", "Home");
 }
Ejemplo n.º 5
0
 public ActionResult Fail(LoginModel login)
 {
     return View();
 }