forked from AcaMate/AcaMate_API
[🐛] 헤더 디비 검증 로직 오류 수정
This commit is contained in:
parent
7fc316520c
commit
fc428d5c85
|
@ -22,11 +22,11 @@ public class HeaderConfigRepository : IHeaderConfig
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetExpectedHeaderValueAsync(string headerName)
|
public async Task<string> GetExpectedHeaderValueAsync(string headerValue)
|
||||||
{
|
{
|
||||||
var config = await _dbContext.APIHeader
|
var config = await _dbContext.APIHeader
|
||||||
.FirstOrDefaultAsync(h => h.h_key == headerName);
|
.FirstOrDefaultAsync(h => h.h_value == headerValue);
|
||||||
return config?.h_value ?? string.Empty;
|
return config?.h_key ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ public class APIHeaderMiddleware
|
||||||
if (context.Request.Headers.TryGetValue(header, out var headerValue) &&
|
if (context.Request.Headers.TryGetValue(header, out var headerValue) &&
|
||||||
!string.IsNullOrWhiteSpace(headerValue))
|
!string.IsNullOrWhiteSpace(headerValue))
|
||||||
{
|
{
|
||||||
var dbValue = await headerConfig.GetExpectedHeaderValueAsync(header);
|
var keyName = await headerConfig.GetExpectedHeaderValueAsync(headerValue);
|
||||||
if (headerValue == dbValue)
|
if (keyName != string.Empty)
|
||||||
{
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class AppController : ControllerBase
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"[{summary}] : 해당 키 유효기간 경과");
|
_logger.LogInformation($"[{summary}] : 해당 키 유효기간 경과");
|
||||||
apiHeader.h_value = headerValue;
|
apiHeader.h_value = headerValue;
|
||||||
|
apiHeader.connect_date = DateTime.Now;
|
||||||
|
|
||||||
if (await _repositoryService.SaveData<APIHeader>(apiHeader))
|
if (await _repositoryService.SaveData<APIHeader>(apiHeader))
|
||||||
{
|
{
|
||||||
|
@ -123,7 +124,7 @@ public class AppController : ControllerBase
|
||||||
var logProject = new LogProject
|
var logProject = new LogProject
|
||||||
{
|
{
|
||||||
create_date = DateTime.Now ,
|
create_date = DateTime.Now ,
|
||||||
log = $"[{summary}] : 해당 키 유효시간 만료로 인한 새 키 부여"
|
log = $"[{summary}] : 새로운 등록으로 인한 새 키 부여"
|
||||||
};
|
};
|
||||||
// 이거 로그 저장 안되는거 확인!
|
// 이거 로그 저장 안되는거 확인!
|
||||||
_logger.LogInformation($"[{summary}] : {logProject.log}");
|
_logger.LogInformation($"[{summary}] : {logProject.log}");
|
||||||
|
@ -151,7 +152,8 @@ public class AppController : ControllerBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string KeyGenerator(string combineText)
|
[NonAction]
|
||||||
|
private string KeyGenerator(string combineText)
|
||||||
{
|
{
|
||||||
using (SHA256 sha256 = SHA256.Create())
|
using (SHA256 sha256 = SHA256.Create())
|
||||||
{
|
{
|
||||||
|
@ -162,20 +164,20 @@ public class AppController : ControllerBase
|
||||||
|
|
||||||
[HttpGet("version")]
|
[HttpGet("version")]
|
||||||
[CustomOperation("앱 버전 확인","앱 버전을 확인해서 업데이트 여부 판단", "시스템")]
|
[CustomOperation("앱 버전 확인","앱 버전을 확인해서 업데이트 여부 판단", "시스템")]
|
||||||
public IActionResult GetVersionData(string type)
|
public async Task<IActionResult> GetVersionData(string type)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(type))
|
if (string.IsNullOrEmpty(type))
|
||||||
{
|
{
|
||||||
return BadRequest(APIResponse.InvalidInputError);
|
return BadRequest(APIResponse.InvalidInputError());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var version = _dbContext.Version.FirstOrDefault(v => v.os_type == (type == "I" ? "VO01" : "VO02"));
|
var version = await _dbContext.Version.FirstOrDefaultAsync(v => v.os_type == (type == "I" ? "VO01" : "VO02"));
|
||||||
|
|
||||||
if (version == null)
|
if (version == null)
|
||||||
{
|
{
|
||||||
return NotFound(APIResponse.NotFoundError);
|
return NotFound(APIResponse.NotFoundError());
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new APIResponseStatus<Version>
|
var response = new APIResponseStatus<Version>
|
||||||
|
@ -203,7 +205,7 @@ public class AppController : ControllerBase
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{ex.Message}\n{ex.StackTrace}");
|
Console.WriteLine($"{ex.Message}\n{ex.StackTrace}");
|
||||||
return StatusCode(500, APIResponse.UnknownError);
|
return StatusCode(500, APIResponse.UnknownError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user