コード例 #1
0
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (Request.Params["username"] != null && Request.Params["username"].Trim() != "")
            {
                string Uid = Request.Params["username"];
                string pwd = Request.Params["password"];
                List<Danyl.SnnuURP.Model.UserInfo> userInfolist = new BLL.UserInfo().GetModelList("Uid=" + Uid + " and Pwd='" + pwd + "'");
                if (userInfolist.Count==1)
                {
                    Danyl.SnnuURP.Model.UserInfo userInfo = userInfolist.FirstOrDefault<Danyl.SnnuURP.Model.UserInfo>();
                    this.HttpContext.Session["userid"] = userInfo.Uid;
                    this.HttpContext.Session["username"] = userInfo.Uname;
                    return Redirect("../MyInfo/Index");
                }
            }
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to 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("", "Invalid login attempt.");
                    return View(model);
            }
        }