Esempio n. 1
0
 public ActionResult Index(LoginViewModel model,string returnUrl)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = SignInManager.PasswordSignIn(model.Email, model.Password,false,false);
     switch (result)
     {
         case SignInStatus.Success:
             return RedirectToLocal(returnUrl);
         default:
             ModelState.AddModelError("", "无效的登录尝试。");
             return View(model);
     }
 }
Esempio n. 2
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);
            }
        }