[성현모] DBProvider추가. LoginContext 변경

This commit is contained in:
SHM
2025-07-17 11:54:42 +09:00
parent 7a12be392a
commit 3c5f27ce68
22 changed files with 265 additions and 323 deletions

View File

@ -1,4 +1,5 @@
using AuthApi.Services;
using Azure.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
@ -6,15 +7,17 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using SystemX.Core;
using SystemX.Core.Controller;
using SystemX.Core.Model.Auth;
using WebApi.Library.Config;
namespace AuthApi.Controllers
{
[Tags("Auth")]
[Route("api/auth")]
[ApiController]
[ApiExplorerSettings(IgnoreApi = true)]
public class AuthController : CommonController
[ApiExplorerSettings(IgnoreApi = false)]
public class AuthController : CommonController<WebApiConfig>
{
private readonly AuthService _authService;
@ -25,36 +28,39 @@ namespace AuthApi.Controllers
_authService = authService;
}
[HttpGet("/health")]
[HttpGet("health")]
public async Task<IResult> Health()
{
Log4net.WriteLine($"[{GetRequestMethod()}:{GetMethodName()}] [Client IP:{GetClientIP()}] [RequestUrl:{GetRequestUrl()}]{Environment.NewLine}", LogType.CONTROLLER);
await Task.CompletedTask;
return Results.Ok("Healthy");
}
[HttpPost("regisger")]
public async Task<IResult> Register([FromBody] RegisterModel request)
public async Task<IResult> Register([FromBody] Register request)
{
// Log4net.WriteLine(GetRequestLog(request).LogModelToString("Request Auth"), LogType.CONTROLLER);
Guid guid = Guid.NewGuid();
RegisterResponseModel response = new RegisterResponseModel();
Log4net.WriteLine($"[Request][{GetRequestMethod()}:{GetMethodName()}][Client IP:{GetClientIP()}][RequestUrl:{GetRequestUrl()}]::({guid}){Environment.NewLine} {request.ToJson()}", LogType.CONTROLLER);
RegisterResponse response = new RegisterResponse();
if (request?.UserID != null && request?.Password != null)
{
response = await _authService.CreateUser(request);
}
// Log4net.WriteLine(GetResponseLog(response).LogModelToString("Response Auth"), LogType.CONTROLLER);
Log4net.WriteLine($"[Response]::({guid}){Environment.NewLine} {response.ToJson()}", LogType.CONTROLLER);
return Results.Ok(response);
}
[HttpPost("login")]
public async Task<IResult> Login([FromBody] LoginModel request)
public async Task<IResult> Login([FromBody] Login request)
{
// Log4net.WriteLine(GetRequestLog(request).LogModelToString("Request Auth"), LogType.CONTROLLER);
Log4net.WriteLine($"[Request]({guid}) api/auth/register{Environment.NewLine} {request.ToJson()}", LogType.CONTROLLER);
LoginResponseModel response = new LoginResponseModel();
LoginResponse response = new LoginResponse();
response.UserID = request.UserID;
response.EC = ERROR_CODE.EC_USER_LOGIN_FAILED;
@ -75,20 +81,20 @@ namespace AuthApi.Controllers
await _authService.UpdateLoginInfo(request, response.RefreshToken);
}
// Log4net.WriteLine(GetResponseLog(response).LogModelToString("Response Auth"), LogType.CONTROLLER);
Log4net.WriteLine($"[Response]({guid}) api/auth/register{Environment.NewLine} {response.ToJson()}", LogType.CONTROLLER);
return Results.Ok(response);
}
[HttpPost("logout")]
public async Task<IResult> Logout([FromBody] LogoutModel request)
public async Task<IResult> Logout([FromBody] Logout request)
{
// Log4net.WriteLine(GetRequestLog(request).LogModelToString("Request Auth"), LogType.CONTROLLER);
Log4net.WriteLine($"[Request]({guid}) api/auth/register{Environment.NewLine} {request.ToJson()}", LogType.CONTROLLER);
var response = _authService.LogoutUser(request);
await Task.CompletedTask;
// Log4net.WriteLine(GetResponseLog(response).LogModelToString("Response Auth"), LogType.CONTROLLER);
Log4net.WriteLine($"[Response]({guid}) api/auth/register{Environment.NewLine} {response.ToJson()}", LogType.CONTROLLER);
return Results.Ok(response);
}
@ -113,7 +119,7 @@ namespace AuthApi.Controllers
};
}
private string GenerateJwtToken(LoginResponseModel loginResponseModel, bool isRefreshToken = false)
private string GenerateJwtToken(LoginResponse loginResponseModel, bool isRefreshToken = false)
{
var claims = new[]
{