Esempio n. 1
0
        public JsonResult dologin(Myuser myuser)
        {
            ResultModel result = new ResultModel();
            int         i      = (HttpContext.Session.GetInt32("ErrorCount") ?? 0);

            if (i >= 3)
            {
                string code = HttpContext.Session.GetString("LoginValidateCode").ToLower();
                if (code != myuser.Verifycode.ToLower().Trim())
                {
                    result.State      = 2;
                    result.Message    = "验证码输入错误!";
                    result.IfValidate = true;
                    return(Json(result));
                }
            }
            result = MyuserBll.Login(myuser.UserCode, myuser.UserPassword, myuser).Result;
            if (result.State == 1)
            {
                HttpContext.Session.SetInt32("ErrorCount", ++i);
                if (i > 2)
                {
                    result.IfValidate = true;
                }
                else
                {
                    result.IfValidate = false;
                }
            }

            if (result.State == 0)
            {
                HttpContext.Session.Remove("LoginValidateCode");
                HttpContext.Session.Remove("ErrorCount");
                CommonUI.SaveUser(myuser, true);
                string returnUrl = TempData["returnUrl"]?.ToString();
                if (returnUrl != null)
                {
                    Redirect(returnUrl);
                }
                else
                {
                    RedirectToAction(nameof(HomeController.Index), "Home");
                }
            }
            return(Json(result));
        }