[성현모] AccountDB Core로 이동

This commit is contained in:
SHM
2025-07-24 16:54:43 +09:00
parent c6fc5328df
commit bb9ed413a7
20 changed files with 151 additions and 173 deletions

View File

@ -20,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebApi.Library.DBContext\WebApi.Library.DBContext.csproj" />
<ProjectReference Include="..\WebApi.Library\WebApi.Library.csproj" />
</ItemGroup>
@ -28,6 +27,9 @@
<Reference Include="SystemX.Core">
<HintPath>..\..\DLL\SystemX.Core.dll</HintPath>
</Reference>
<Reference Include="SystemX.Core.DB">
<HintPath>..\..\DLL\SystemX.Core.DB.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -1,5 +1,4 @@
using AuthApi.Services;
using Azure.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;

View File

@ -1,14 +1,9 @@
using AuthApi.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.IdentityModel.Tokens;
using System;
using System.ComponentModel;
using System.Text;
using SystemX.Core.Services;
using WebApi.Library.Config;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
string configDir = @"../../Config";
string configFileName = "WebApi.AuthApi.Config.json";

View File

@ -2,12 +2,9 @@
using SystemX.Core.Services;
using SystemX.Core;
using WebApi.Library.Config;
using SystemX.Core.Config.Model;
using System.Data;
using SystemX.Core.DB;
using Microsoft.EntityFrameworkCore;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
namespace AuthApi.Services
{
@ -45,25 +42,25 @@ namespace AuthApi.Services
{
if (context is not null)
{
var user = await context.TUsers.AsNoTracking().Where(x => x.CUserId.ToLower() == registerModel.UserID.ToLower()).ToListAsync();
var user = await context.tUsers.AsNoTracking().Where(x => x.cUserID.ToLower() == registerModel.UserID.ToLower()).ToListAsync();
if (user?.Count <= 0)
{
string auid = Guid.NewGuid().ToString();
//user
TUser newUser = new TUser
tUser newUser = new tUser
{
CAuid = auid,
CUserId = registerModel.UserID,
CPasswordHashed = registerModel.Password,
CCreateDateTime = DateTime.Now,
CLastLoginDateTime = new DateTime()
cAuid = auid,
cUserID = registerModel.UserID,
cPasswordHashed = registerModel.Password,
cCreateDateTime = DateTime.Now,
cLastLoginDateTime = new DateTime()
};
//role
TRole newUserRole = new TRole
tRole newUserRole = new tRole
{
CAuid = auid,
CRoleId = Convert.ToByte(registerModel.Role),
CRoleName = registerModel.Role.ToString()
cAuid = auid,
cRoleID = Convert.ToByte(registerModel.Role),
cRoleName = registerModel.Role.ToString()
};
using (var transaction = await context.CreateTransactionAsync())
@ -119,29 +116,29 @@ namespace AuthApi.Services
using (var transaction = await context.CreateTransactionAsync(IsolationLevel.ReadUncommitted))
{
//select user
var selectUser = await context.TUsers.AsNoTracking().FirstOrDefaultAsync(x => x.CUserId.ToLower() == loginModel!.UserID!.ToLower());
var selectUser = await context.tUsers.AsNoTracking().FirstOrDefaultAsync(x => x.cUserID.ToLower() == loginModel!.UserID!.ToLower());
if (selectUser is not null)
{
if (selectUser.CPasswordHashed == loginModel?.Password)
if (selectUser.cPasswordHashed == loginModel?.Password)
{
//select role
var selectRole = await context.TRoles.FindAsync(selectUser.CAuid);
var selectRole = await context.tRoles.FindAsync(selectUser.cAuid);
if (selectRole != null)
{
response.Role = (UserRole)Enum.Parse(typeof(UserRole), selectRole.CRoleId.ToString());
response.RoleName = selectRole.CRoleName;
response.Role = (UserRole)Enum.Parse(typeof(UserRole), selectRole.cRoleID.ToString());
response.RoleName = selectRole.cRoleName;
}
Session.Add(response);
if (selectUser.CState == (byte)UserState.Active)
if (selectUser.cState == (byte)UserState.Active)
{
response.EC = ERROR_CODE.EC_OK;
}
else if (selectUser.CState == (byte)UserState.Inactive)
else if (selectUser.cState == (byte)UserState.Inactive)
{
response.EC = ERROR_CODE.EC_USER_LOGIN_INAVTIVE;
}
else if (selectUser.CState == (byte)UserState.Block)
else if (selectUser.cState == (byte)UserState.Block)
{
response.EC = ERROR_CODE.EC_USER_LOGIN_BLOCKED;
}
@ -185,7 +182,7 @@ namespace AuthApi.Services
{
if (context is not null)
{
var selectUser = await context.TUsers.AsNoTracking().FirstOrDefaultAsync(x => x.CUserId.ToLower() == loginModel!.UserID!.ToLower());
var selectUser = await context.tUsers.AsNoTracking().FirstOrDefaultAsync(x => x.cUserID.ToLower() == loginModel!.UserID!.ToLower());
if (selectUser is not null)
{
using (var transaction = await context.CreateTransactionAsync())
@ -193,24 +190,24 @@ namespace AuthApi.Services
try
{
//user info
selectUser.CLastLoginDateTime = DateTime.Now;
selectUser.cLastLoginDateTime = DateTime.Now;
context.Update(selectUser);
//refresh token
var findRefreshToken = await context.TRefreshTokens.AsNoTracking().FirstOrDefaultAsync(x => x.CAuid == selectUser.CAuid);
var findRefreshToken = await context.tRefreshTokens.AsNoTracking().FirstOrDefaultAsync(x => x.cAuid == selectUser.cAuid);
//null이면(없으면) add
if (findRefreshToken == null)
{
await context.AddAsync(new TRefreshToken
await context.AddAsync(new tRefreshToken
{
CAuid = selectUser.CAuid,
CRefreshToken = $"{RefreshToken}"
cAuid = selectUser.cAuid,
cRefreshToken= $"{RefreshToken}"
});
}
//있으면 update
else
{
findRefreshToken.CRefreshToken = $"{RefreshToken}";
findRefreshToken.cRefreshToken = $"{RefreshToken}";
context.Update(findRefreshToken);
}
@ -264,10 +261,10 @@ namespace AuthApi.Services
return response;
}
private AccountDbContext? GetAccountDBContext(DbContextProvider provider, int dbID)
private AccountDBContext? GetAccountDBContext(DbContextProvider provider, int dbID)
{
var connectionString = _configService?.GetConfig()?.DataBase?.Find(x => x.DBID == dbID);
return provider?.GetDBContext<AccountDbContext>($"{connectionString?.DBName}");
return provider?.GetDBContext<AccountDBContext>($"{connectionString?.DBName}");
}
}
}