Beispiel #1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Index(Login_IndexVD vdForm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vdForm));
            }
            string errorMsg = null;

            var userInfo = _userInfoService.GetUserInfo(vdForm.Name);

            if (userInfo == null)
            {
                errorMsg = "账号或密码错误!错误代码:101。";
            }
            else if (_userInfoService.TryLogin(vdForm.Name, vdForm.Password, true) == null)
            {
                errorMsg = "账号或密码错误!错误代码:102。";
            }

            if (!errorMsg.IsNullOrEmpty() || !ModelState.IsValid)
            {
                vdForm.MessagerList = new List <Messager>
                {
                    new Messager(Senparc.Ncf.Core.Enums.MessageType.danger, errorMsg)
                };
                return(View(vdForm));
            }

            if (vdForm.ReturnUrl.IsNullOrEmpty())
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(Redirect(vdForm.ReturnUrl.UrlDecode()));
        }
Beispiel #2
0
        public ActionResult Index(string returnUrl)
        {
            Login_IndexVD vd = new Login_IndexVD()
            {
                ReturnUrl    = returnUrl,
                MessagerList = new List <Messager>(),
            };

            if (TempData["AuthorityNotReach"] != null && TempData["AuthorityNotReach"].ToString() == "TRUE")
            {
                vd.MessagerList.Add(new Messager(Core.Enums.MessageType.error, "您无权访问此页面或执行此操作!"));
                vd.AuthorityNotReach = true;
            }

            vd.IsLogined = this.HttpContext.User.Identity.IsAuthenticated;

            var tryLoginTimes = 0;

            if (Session["TryLoginTimes"] != null)
            {
                tryLoginTimes = (int)Session["TryLoginTimes"];
            }
            vd.ShowCheckCode = tryLoginTimes > SiteConfig.TryLoginTimes;

            return(View(vd));
        }
Beispiel #3
0
        public async Task <IActionResult> Index(string returnUrl)
        {
            //是否已经登录
            var authenticate = await HttpContext.AuthenticateAsync(AdminAuthorizeAttribute.AuthenticationScheme);

            if (authenticate.Succeeded)
            {
                if (returnUrl.IsNullOrEmpty())
                {
                    return(RedirectToAction("Index", "Home"));
                }
                return(Redirect(returnUrl.UrlDecode()));
            }
            Login_IndexVD vd = new Login_IndexVD
            {
                ReturnUrl    = returnUrl,
                MessagerList = new List <Messager>(),
                IsLogined    = this.HttpContext.User.Identity.IsAuthenticated,
            };

            return(View(vd));
        }
Beispiel #4
0
        //[ValidateAntiForgeryToken]
        public ActionResult Index(Login_IndexVD vdForm)
        {
            //this.Validator(vdForm.Checkcode, "验证码", "Checkcode", null).ValidateCheckCode(CheckCodeKind.Login, true);
            //验证域名
            string errorMsg = null;

            IAdminUserInfoService adminUserInfoService = null;
            AdminUserInfo         adminUserInfo        = null;

            if (vdForm.UserName.IsNullOrEmpty())
            {
                errorMsg = "请填写账号!";
            }
            else if (vdForm.Password.IsNullOrEmpty())
            {
                errorMsg = "请填写密码!";
            }
            else
            {
                if (Session["TryLoginTimes"] != null)
                {
                    //TODO:验证码
                }

                if (ModelState.IsValid)
                {
                    adminUserInfoService = StructureMap.ObjectFactory.GetInstance <IAdminUserInfoService>();
                    adminUserInfo        = adminUserInfoService.GetUserInfo(vdForm.UserName);
                    if (adminUserInfo == null)
                    {
                        errorMsg = "账号或密码错误!错误代码:101。";
                    }
                    //else if (userInfo.Locked)
                    //{
                    //    errorMsg = "账号已被锁定,无法登录。";
                    //}
                    else if (adminUserInfoService.TryLogin(vdForm.UserName, vdForm.Password, true) == null)
                    {
                        errorMsg = "账号或密码错误!错误代码:102。";
                    }
                }
            }

            if (!errorMsg.IsNullOrEmpty() || !ModelState.IsValid)
            {
                var tryLoginTimes = 0;
                if (Session["TryLoginTimes"] != null)
                {
                    tryLoginTimes = (int)Session["TryLoginTimes"];
                }

                vdForm.ShowCheckCode = tryLoginTimes >= SiteConfig.TryLoginTimes;

                Session["TryLoginTimes"] = tryLoginTimes + 1;

                vdForm.MessagerList = new List <Messager>();
                vdForm.MessagerList.Add(new Messager(Core.Enums.MessageType.error, errorMsg));
                return(View(vdForm));
            }
            Session["TryLoginTimes"] = null;//清空登录次数

            LogUtility.AdminUserInfo.InfoFormat("用户登录成功:{0}", vdForm.UserName);
            Session["AdminLogin"] = "******";

            if (vdForm.ReturnUrl.IsNullOrEmpty())
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(Redirect(vdForm.ReturnUrl.UrlDecode()));
            }
        }