public async Task <IActionResult> Get() { APIResult apiResult; var records = await(await holuserService.GetAsync()).ToListAsync(); var result = mapper.Map <List <HoluserDto> >(records); apiResult = APIResultFactory.Build(true, StatusCodes.Status200OK, ErrorMessageEnum.None, payload: result); return(Ok(apiResult)); }
public async Task <IActionResult> RefreshToken() { APIResult apiResult; await Task.Yield(); LoginRequestDto loginRequestDTO = new LoginRequestDto() { Account = User.FindFirst(JwtRegisteredClaimNames.Sid)?.Value, }; Holuser user = await holuserService.GetAsync(Convert.ToInt32(loginRequestDTO.Account)); if (user == null) { apiResult = APIResultFactory.Build(false, StatusCodes.Status401Unauthorized, ErrorMessageEnum.沒有發現指定的該使用者資料); return(BadRequest(apiResult)); } string token = GenerateToken(user); string refreshToken = GenerateRefreshToken(user); LoginResponseDto LoginResponseDTO = new LoginResponseDto() { Account = loginRequestDTO.Account, Id = 0, Name = loginRequestDTO.Account, Token = token, TokenExpireMinutes = Convert.ToInt32(configuration["Tokens:JwtExpireMinutes"]), RefreshToken = refreshToken, RefreshTokenExpireDays = Convert.ToInt32(configuration["Tokens:JwtRefreshExpireDays"]), }; apiResult = APIResultFactory.Build(true, StatusCodes.Status200OK, ErrorMessageEnum.None, payload: LoginResponseDTO); return(Ok(apiResult)); }