Пример #1
0
        private async Task <string> LogLoginErrorInfo(string user_name, string password, Func <Task <string> > func)
        {
            if (!ValidateHelper.IsAllPlumpString(user_name, password))
            {
                return("登录信息未填写");
            }
            if (await this._LoginErrorLogBll.GetRecentLoginErrorTimes(user_name) > 5)
            {
                return("你短时间内有多次错误登录记录,请稍后再试");
            }
            var res = await func.Invoke();

            if (ValidateHelper.IsPlumpString(res))
            {
                var errinfo = new LoginErrorLogModel()
                {
                    LoginKey = user_name,
                    LoginPwd = password,
                    LoginIP  = this.X.IP,
                    ErrorMsg = res
                };
                var logres = await this._LoginErrorLogBll.AddLoginErrorLog(errinfo);

                if (ValidateHelper.IsPlumpString(logres))
                {
                    new Exception($"记录错误登录日志错误:{logres}").AddErrorLog();
                }
            }
            return(res);
        }
Пример #2
0
        public ActionResult LoginAction(string email, string pass)
        {
            return(RunAction(() =>
            {
                if (!ValidateHelper.IsAllPlumpString(email, pass))
                {
                    return GetJsonRes("账户密码不能为空");
                }

                //检查登录尝试
                var err_count = _LoginErrorLogBll.GetRecentLoginErrorTimes(email);
                if (err_count > 5)
                {
                    return GetJsonRes($"你短时间内有{err_count}次错误登录记录,请稍后再试");
                }
                //开始登录
                string msg = string.Empty;
                var model = _IUserService.LoginByPassWord(email, pass, ref msg);
                if (model != null && model.UserToken?.Length > 0)
                {
                    //记录登录状态
                    AppContext.GetObject <LoginStatus>().SetUserLogin(loginuser: new LoginUserInfo()
                    {
                    });
                    return GetJson(new { success = true, msg = "登陆成功" });
                }
                //登录错误,记录错误记录
                var errorLoginLog = new LoginErrorLogModel()
                {
                    LoginKey = ConvertHelper.GetString(email),
                    LoginPwd = ConvertHelper.GetString(pass),
                    LoginIP = ConvertHelper.GetString(this.X.IP),
                    LoginTime = DateTime.Now
                };
                var errorloghandler = _LoginErrorLogBll.AddLoginErrorLog(errorLoginLog);
                if (ValidateHelper.IsPlumpString(errorloghandler))
                {
                    LogHelper.Info(this.GetType(), "记录错误登录日志错误:" + errorloghandler);
                }

                return GetJson(new { success = false, msg = msg });
            }));
        }