[성현모] AuthApi 분리

This commit is contained in:
SHM
2025-07-15 10:16:26 +09:00
parent 20f1e7e7e5
commit 7a12be392a
52 changed files with 1931 additions and 60 deletions

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace SystemX.Core.Config.Model
{
public class Auth
{
//jwt common
[JsonPropertyName("issuer")]
public string? issuer { get; set; }
[JsonPropertyName("audience")]
public string? audience { get; set; }
//access token
[JsonPropertyName("accessTokenSecret")]
public string? accessTokenSecret { get; set; }
[JsonPropertyName("accessTokenExpires")]
public uint? accessTokenExpires { get; set; }
//refresh token
[JsonPropertyName("refreshTokenSecret")]
public string? refreshTokenSecret { get; set; }
[JsonPropertyName("refreshTokenExpires")]
public uint? refreshTokenExpires { get; set; }
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using SystemX.Core.DB.DBContext.AccountDB.Tables;
namespace SystemX.Core.DB.DBContext.AccountDB.Context;
public partial class AccountDbContext : DbContext
{
public AccountDbContext()
{
}
public AccountDbContext(DbContextOptions<AccountDbContext> options)
: base(options)
{
}
public virtual DbSet<TRefreshToken> TRefreshTokens { get; set; }
public virtual DbSet<TRole> TRoles { get; set; }
public virtual DbSet<TUser> TUsers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseSqlServer("server=127.0.0.1; user id=SystemX; password=X; database=AccountDB; TrustServerCertificate=true;");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TRefreshToken>(entity =>
{
entity.HasKey(e => e.CAuid).HasName("PK__tRefresh__FBF0855465EB95AB");
entity.ToTable("tRefreshToken");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CRefreshToken)
.HasMaxLength(1000)
.HasColumnName("cRefreshToken");
});
modelBuilder.Entity<TRole>(entity =>
{
entity.HasKey(e => e.CAuid).HasName("PK__tRole__FBF085540BB887D7");
entity.ToTable("tRole");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CRoleId).HasColumnName("cRoleID");
entity.Property(e => e.CRoleName)
.HasMaxLength(20)
.HasColumnName("cRoleName");
});
modelBuilder.Entity<TUser>(entity =>
{
entity.HasKey(e => e.CUserId).HasName("PK__tUser__A75DC19A721265FF");
entity.ToTable("tUser");
entity.Property(e => e.CUserId)
.HasMaxLength(50)
.HasColumnName("cUserID");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CCreateDateTime).HasColumnName("cCreateDateTime");
entity.Property(e => e.CLastLoginDateTime).HasColumnName("cLastLoginDateTime");
entity.Property(e => e.CPasswordHashed)
.HasMaxLength(250)
.HasColumnName("cPasswordHashed");
entity.Property(e => e.CState).HasColumnName("cState");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace SystemX.Core.DB.DBContext.AccountDB.Tables;
public partial class TRefreshToken
{
public string CAuid { get; set; } = null!;
public string CRefreshToken { get; set; } = null!;
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace SystemX.Core.DB.DBContext.AccountDB.Tables;
public partial class TRole
{
public string CAuid { get; set; } = null!;
public byte CRoleId { get; set; }
public string CRoleName { get; set; } = null!;
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
namespace SystemX.Core.DB.DBContext.AccountDB.Tables;
public partial class TUser
{
public string CUserId { get; set; } = null!;
public string CAuid { get; set; } = null!;
public string CPasswordHashed { get; set; } = null!;
public byte CState { get; set; }
public DateTime CCreateDateTime { get; set; }
public DateTime? CLastLoginDateTime { get; set; }
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core
{
public enum ERROR_CODE
{
//기본 에러
EC_NONE = 0,
EC_OK = 1,
//DB 관련 에러
EC_DEFAULT_ERROR = 1000,
EC_DATABASE_ERROR = 1001,
//유저 관련 에러
EC_USER_REGISTER_FAILED = 2000,
EC_USER_REGISTER_EXIST = 2001,
EC_USER_REGISTER_CONFIRM_PASSWORD_ERROR = 2002,
EC_USER_LOGIN_FAILED = 2100,
EC_USER_LOGIN_NOT_EXIST = 2101,
EC_USER_LOGIN_INVALID_PASSWORD = 2102,
EC_USER_LOGIN_INAVTIVE = 2103,
EC_USER_LOGIN_BLOCKED = 2104,
EC_USER_LOGOUT_FAILED = 2200
}
}

View File

@ -57,6 +57,8 @@ public static class Log4net
public static bool IsConfigLoad { get; set; } = false;
public static string Log4netConfigPath { get; } = @"../../Config/log4net.config";
//로그 사용여부
public static bool IsDebugEnabled { get; set; } = true;
public static bool IsDBEnabled { get; set; } = true;
@ -70,7 +72,7 @@ public static class Log4net
static Log4net()
{
string log4netConfigPath = @"../Config/log4net.config";
string log4netConfigPath = Log4netConfigPath;
if (File.Exists(log4netConfigPath) == true)
{
@ -82,7 +84,7 @@ public static class Log4net
IsConfigLoad = OpenConfig(log4netConfigPath);
}
private static bool OpenConfig(string path)
{
bool result = true;

View File

@ -0,0 +1,34 @@
using log4net.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
//로그인 요청 모델
public class LoginModel
{
[Required]
public string? UserID { get; set; }
[Required]
public string? Password { get; set; }
}
//로그인 응답 모델
public class LoginResponseModel
{
public string? UserID { get; set; }
public UserRole Role { get; set; }
public string? RoleName { get; set; }
public string? AccessToken { get; set; }
public long AccessTokenExpired { get; set; }
public string? RefreshToken { get; set; }
public ERROR_CODE? EC { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using log4net.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
public class LogoutModel
{
[Required]
public string? UserID { get; set; }
}
public class LogoutResponseModel
{
public string? UserID { get; set; }
public ERROR_CODE? EC { get; set; }
}
}

View File

@ -0,0 +1,35 @@
using log4net.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
//유저 등록 모델
public class RegisterModel
{
[Required]
public string UserID { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string PasswordConfirm { get; set; } = string.Empty;
[Required]
public UserRole Role { get; set; } = UserRole.User;
}
public class RegisterResponseModel
{
public string? UserID { get; set; }
public UserRole Role { get; set; }
public string? RoleName { get; set; }
public ERROR_CODE? EC { get; set; } = ERROR_CODE.EC_USER_REGISTER_FAILED;
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
public class UserModel
{
//public TUser? TUser { get; set; }
//public TRole? TRole { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
//User 권한
public enum UserRole : byte
{
None = 0,
Ananymous = 1,
User = 10,
Admin = 11,
SuperUser = 20,
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemX.Core.Model.Auth
{
public enum UserState : byte
{
Inactive = 0,
Active = 1,
Block = 2
}
}

View File

@ -9,18 +9,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>9999</WarningLevel>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<WarningLevel>9999</WarningLevel>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="log4net" Version="3.0.4" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>