コード例 #1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResponseBase> ProcessAction(HttpContext httpContext, LoginRequest request)
        {
            var response = new ResponseBase();

            if (!await CheckUserLoginFailedRecord(request.UserAccount))
            {
                return(response.GetResponseError(StatusCode.Login20003, "登录失败次数超过限制"));
            }
            if (string.IsNullOrEmpty(request.UserAccount) || string.IsNullOrEmpty(request.UserPassword))
            {
                return(response.GetResponseBadRequest());
            }
            var pwd  = CryptogramHelper.Encrypt3DES(request.UserPassword);
            var user = await _sysUserBll.GetSysUser(request.UserAccount, pwd);

            if (user == null)
            {
                await _sysUserBll.AddUserLoginFailedRecord(request.UserAccount, SystemConfig.UserLoginConfig.LoginFailedMaxCount, SystemConfig.UserLoginConfig.LoginFailedTimeOut);

                return(response.GetResponseError(StatusCode.Login20001, "帐号或密码错误"));
            }
            if (user.StatusFlag == (int)UserStatusFlagEnum.Disable)
            {
                return(response.GetResponseError(StatusCode.Login20002, "帐号被禁用"));
            }
            var loginView = await GetLoginView(user);

            var userRole = await _sysUserRoleBll.GetSysUserRole(user.UserRoleId);

            AppTicket.SetAppTicket(httpContext, user, userRole);
            await _sysUserBll.UpdateUserLastLoginTime(user.UserId, DateTime.Now);

            await _sysUserBll.RemoveUserLoginFailedRecord(request.UserAccount);

            AddUserLoginLog(user);
            return(response.GetResponseSuccess(loginView));
        }