/// <summary> /// 用户密码登陆 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <LoginOutput> LoginAsync(LoginInput input) { var rediscontect = _config.StringGet("RedisDefaultServer"); var redis = _redisClient.GetDatabase(rediscontect, 5); var kv = await redis.StringGetAsync($"ImgCode:{input.Guid}"); if (kv.IsNullOrEmpty || kv.ToString().ToLower() != input.ImgCode.ToLower()) { throw new BucketException("GO_2003", "图形验证码错误"); } // 用户验证 var userInfo = await _userDbRepository.GetFirstAsync(it => it.UserName == input.UserName); if (userInfo == null) { throw new BucketException("GO_0004007", "账号不存在"); } if (userInfo.State != 1) { throw new BucketException("GO_0004008", "账号状态异常"); } if (userInfo.Password != Encrypt.SHA256(input.Password + userInfo.Salt)) { throw new BucketException("GO_4009", "账号或密码错误"); } // 用户角色 //_userDbRepository.AsQueryable().Context.Queryable<>() var roleList = await _userDbRepository.AsQueryable().Context.Queryable <RoleInfo, UserRoleInfo>((role, urole) => new object[] { JoinType.Inner, role.Id == urole.RoleId }) .Where((role, urole) => urole.Uid == userInfo.Id) .Where((role, urole) => role.IsDel == false) .Select((role, urole) => new { role.Key }) .ToListAsync(); // token返回 var token = _authRepository.CreateAccessToken(new UserTokenDto { Email = userInfo.Email, Id = userInfo.Id, Mobile = userInfo.Mobile, RealName = userInfo.RealName, }, roleList.Select(it => it.Key).ToList()); return(new LoginOutput { Data = new { AccessToken = $"Bearer {token}", Expire = DateTimeOffset.Now.AddHours(4).ToUnixTimeSeconds(), RealName = userInfo.RealName.SafeString(), Mobile = userInfo.Mobile.SafeString(), userInfo.Id } }); }
/// <summary> /// 查询网关路由列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <QueryApiGatewayReRouteListOutput> QueryApiGatewayReRouteList(QueryApiGatewayReRouteListInput input) { int count = 0; var listResult = await _routeDbRepository.AsQueryable() .WhereIF(input.GatewayId > 0, it => it.GatewayId == input.GatewayId) .WhereIF(input.State > -1, it => it.State == input.State) .ToPageListAsync(input.PageIndex, input.PageSize, count); return(new QueryApiGatewayReRouteListOutput { CurrentPage = input.PageIndex, Total = listResult.Count, Data = listResult }); }