Esempio n. 1
0
        /// <summary>
        /// 密码是否遵守规则
        /// </summary>
        /// <returns></returns>
        private bool CheckPasswordStronger(string password)
        {
            var result = false;

            result = PasswordStrengthDetectionService.IsMatch(password);
            return(result);
        }
Esempio n. 2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {            //通过微信登录
            var Isweixinlogin = model.IsWeiXinLogin == "1" && !string.IsNullOrEmpty(model.WeixinUser);

            ViewBag.IsWeiXinAuth = !string.IsNullOrEmpty(model.WeixinUser);
            returnUrl            = !string.IsNullOrWhiteSpace(returnUrl) ? returnUrl : (string.IsNullOrEmpty(model.Stateurl) ? "~/Manage/index" : model.Stateurl);
            if (Isweixinlogin)
            {
                ViewBag.WeiXinUser = model.WeixinUser;
                ViewBag.WeiXinUrl  = returnUrl;
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            #region 密码安全监测
            var isDetectionOn = PasswordStrengthDetectionService.IsDetectionOn();
            if (isDetectionOn)
            {
                var ismatch = PasswordStrengthDetectionService.IsMatch(model.Password.Trim());
                if (ismatch)
                {
                    Session["IsPasswordStronger"] = true;
                }
                else
                {
                    Session["IsPasswordStronger"] = false;
                }
            }
            #endregion
            var result = await SignInHelper.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout : false);


            //var user = await UserManager.FindByNameAsync(model.UserName);
            //var roles = await UserManager.GetRolesAsync(user.Id);
            log4net.LogManager.GetLogger("RollingLog").Info(model.UserName + " Log in: " + result.ToString());
            switch (result)
            {
            case MvcBackend.App_Start.SignInStatus.Success:
                Session["MyMenu"] = null;
                if (Isweixinlogin)
                {
                    var user = ReadOnlyRepository.GetForUpdate(e => e.UserName == model.UserName.Trim());
                    //if (user == null) return Redirect(WeiXinAuthHtml.Replace("[url]", returnUrl));

                    if (string.IsNullOrEmpty(user.WeiXinAuthId))
                    {
                        user.WeiXinAuthId = model.WeixinUser;
                        Repository.Update(user);
                    }
                    else
                    {
                        var weixinuser = ReadOnlyRepository.Get(e => e.WeiXinAuthId == model.WeixinUser);
                        if (weixinuser != null && weixinuser.UserName != model.UserName)
                        {
                            ModelState.AddModelError("", "微信企业号已经认证过。");
                            return(View(model));
                        }
                    }
                }
                return(RedirectToLocal(returnUrl));

            case MvcBackend.App_Start.SignInStatus.LockedOut:
                return(View("Lockout"));

            case MvcBackend.App_Start.SignInStatus.RequiresTwoFactorAuthentication:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl }));

            case MvcBackend.App_Start.SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "登陆名或密码错误。");
                return(View(model));
            }
        }