public ActionResult Login(LoginViewModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if (!Membership.ValidateUser(model.Login, model.Password))
         {
             FormsAuthentication.SetAuthCookie(model.Login, model.RememberMe);
             if (Request.IsAjaxRequest())
             {
                 if (HttpContext.User.Identity != null)
                 {
                     return Content(model.Login);
                 }
                 return Content(string.Empty);
             }
             else
             {
                 if(returnUrl!=null)
                 {
                     return Redirect(returnUrl);
                 }
                 else
                 {
                     return RedirectToAction("Index", "Home");
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "The user name or password provided is incorrect.");
         }
     }
     return View(model);
 }
Exemplo n.º 2
0
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
              {
             return View();
              }

              if (provider.Authenticate(model.UserName, model.Password))
              {
             return Redirect((string)Session["returnUrl"] ?? Url.Action("Index", "Admin"));
              }
              else
              {
             ModelState.AddModelError("", "Неправильно введено Имя пользователя и/или пароль!");
             return View();
              }
        }
Exemplo n.º 3
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // 这不会计入到为执行帐户锁定而统计的登录失败次数中
            // 若要在多次输入错误密码的情况下触发帐户锁定,请更改为 shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "无效的登录尝试。");
                    return View(model);
            }
        }