Compare commits
4 Commits
b2c8b35cdd
...
adb6e9e875
| Author | SHA1 | Date | |
|---|---|---|---|
| adb6e9e875 | |||
| 164d121992 | |||
| 6423713305 | |||
| a039bb53a4 |
@@ -1,9 +1,10 @@
|
|||||||
@page "/login"
|
@page "/login"
|
||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
@using Microsoft.AspNetCore.Authentication
|
|
||||||
@using Microsoft.AspNetCore.Authentication.Cookies
|
|
||||||
@layout TaxBaik.Admin.Components.Layout.BlankLayout
|
@layout TaxBaik.Admin.Components.Layout.BlankLayout
|
||||||
@attribute [AllowAnonymous]
|
@attribute [AllowAnonymous]
|
||||||
|
@inject AuthService AuthService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject CustomAuthenticationStateProvider AuthStateProvider
|
||||||
|
|
||||||
<PageTitle>로그인</PageTitle>
|
<PageTitle>로그인</PageTitle>
|
||||||
|
|
||||||
@@ -24,7 +25,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
||||||
Size="Size.Large" OnClick="HandleLogin">로그인</MudButton>
|
Size="Size.Large" OnClick="HandleLogin" Disabled="isLoading">
|
||||||
|
@if (isLoading)
|
||||||
|
{
|
||||||
|
<MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
|
||||||
|
<span>로그인 중...</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span>로그인</span>
|
||||||
|
}
|
||||||
|
</MudButton>
|
||||||
</MudForm>
|
</MudForm>
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
@@ -32,30 +43,43 @@
|
|||||||
@code {
|
@code {
|
||||||
private MudForm form;
|
private MudForm form;
|
||||||
private bool isFormValid = false;
|
private bool isFormValid = false;
|
||||||
|
private bool isLoading = false;
|
||||||
private string errorMessage = "";
|
private string errorMessage = "";
|
||||||
|
|
||||||
private LoginModel model = new();
|
private LoginModel model = new();
|
||||||
|
|
||||||
private async Task HandleLogin()
|
private async Task HandleLogin()
|
||||||
{
|
{
|
||||||
// 기본 사용자명: admin / 비밀번호: admin123
|
if (isLoading)
|
||||||
if (model.Username == "admin" && model.Password == "admin123")
|
return;
|
||||||
|
|
||||||
|
isLoading = true;
|
||||||
|
errorMessage = "";
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// 임시: 대시보드로 리다이렉트 (향후 실제 쿠키 인증으로 개선)
|
var token = await AuthService.AuthenticateAndGenerateTokenAsync(model.Username, model.Password);
|
||||||
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", forceLoad: true);
|
|
||||||
}
|
if (token == null)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
|
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
|
||||||
}
|
isLoading = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inject]
|
await AuthStateProvider.LoginAsync(token);
|
||||||
private NavigationManager NavigationManager { get; set; }
|
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", forceLoad: false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
errorMessage = "로그인 중 오류가 발생했습니다.";
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class LoginModel
|
private class LoginModel
|
||||||
{
|
{
|
||||||
public string Username { get; set; }
|
public string Username { get; set; } = "";
|
||||||
public string Password { get; set; }
|
public string Password { get; set; } = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
|
|
||||||
|
<CascadingAuthenticationState>
|
||||||
<Router AppAssembly="typeof(Program).Assembly">
|
<Router AppAssembly="typeof(Program).Assembly">
|
||||||
<Found Context="routeData">
|
<Found Context="routeData">
|
||||||
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
|
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
|
||||||
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
||||||
</Found>
|
</Found>
|
||||||
<NotFound>
|
<NotFound>
|
||||||
@@ -12,3 +14,4 @@
|
|||||||
</LayoutView>
|
</LayoutView>
|
||||||
</NotFound>
|
</NotFound>
|
||||||
</Router>
|
</Router>
|
||||||
|
</CascadingAuthenticationState>
|
||||||
|
|||||||
@@ -7,3 +7,5 @@
|
|||||||
@using Microsoft.AspNetCore.Components.Authorization
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using MudBlazor
|
@using MudBlazor
|
||||||
|
@using TaxBaik.Admin.Services
|
||||||
|
@attribute [Authorize]
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using MudBlazor.Services;
|
using MudBlazor.Services;
|
||||||
|
using TaxBaik.Admin.Services;
|
||||||
using TaxBaik.Application;
|
using TaxBaik.Application;
|
||||||
using TaxBaik.Infrastructure;
|
using TaxBaik.Infrastructure;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
builder.Services.AddScoped<AuthService>();
|
||||||
.AddCookie(opts => {
|
builder.Services.AddScoped<CustomAuthenticationStateProvider>();
|
||||||
opts.LoginPath = "/login";
|
builder.Services.AddScoped<AuthenticationStateProvider>(sp => sp.GetRequiredService<CustomAuthenticationStateProvider>());
|
||||||
opts.ExpireTimeSpan = TimeSpan.FromHours(8);
|
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||||
opts.Cookie.SameSite = SameSiteMode.Lax;
|
builder.Services.AddCascadingAuthenticationState();
|
||||||
});
|
|
||||||
builder.Services.AddAuthorizationCore();
|
builder.Services.AddAuthorizationCore();
|
||||||
|
|
||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
@@ -44,7 +44,9 @@ builder.Services.AddSingleton(versionInfo);
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Run migrations on startup
|
// Run migrations on startup (non-blocking for development)
|
||||||
|
try
|
||||||
|
{
|
||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var connectionFactory = scope.ServiceProvider.GetRequiredService<TaxBaik.Domain.Interfaces.IDbConnectionFactory>();
|
var connectionFactory = scope.ServiceProvider.GetRequiredService<TaxBaik.Domain.Interfaces.IDbConnectionFactory>();
|
||||||
@@ -53,6 +55,11 @@ using (var scope = app.Services.CreateScope())
|
|||||||
var migrationRunner = new TaxBaik.Infrastructure.Data.MigrationRunner(cs, connectionFactory);
|
var migrationRunner = new TaxBaik.Infrastructure.Data.MigrationRunner(cs, connectionFactory);
|
||||||
await migrationRunner.RunAsync();
|
await migrationRunner.RunAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"⚠️ Migration warning (non-blocking): {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@@ -64,7 +71,6 @@ app.UsePathBase("/taxbaik/admin");
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthentication();
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseAntiforgery();
|
app.UseAntiforgery();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text;
|
||||||
|
using BCrypt.Net;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using TaxBaik.Domain.Entities;
|
||||||
|
using TaxBaik.Domain.Interfaces;
|
||||||
|
|
||||||
|
namespace TaxBaik.Admin.Services;
|
||||||
|
|
||||||
|
public class AuthService
|
||||||
|
{
|
||||||
|
private readonly IAdminUserRepository _adminUserRepository;
|
||||||
|
private readonly ILogger<AuthService> _logger;
|
||||||
|
private readonly string _jwtSecretKey;
|
||||||
|
private readonly int _tokenExpirationMinutes = 480; // 8시간
|
||||||
|
|
||||||
|
public AuthService(IAdminUserRepository adminUserRepository, ILogger<AuthService> logger, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_adminUserRepository = adminUserRepository;
|
||||||
|
_logger = logger;
|
||||||
|
_jwtSecretKey = configuration["Jwt:SecretKey"] ?? throw new InvalidOperationException("Missing 'Jwt:SecretKey' configuration.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string?> AuthenticateAndGenerateTokenAsync(string username, string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _adminUserRepository.GetByUsernameAsync(username);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("로그인 시도: 존재하지 않는 사용자 '{Username}'", username);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BCrypt.Net.BCrypt.Verify(password, user.PasswordHash))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("로그인 시도: 잘못된 비밀번호 '{Username}'", username);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("로그인 성공: {Username}", username);
|
||||||
|
return GenerateJwtToken(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateJwtToken(AdminUser user)
|
||||||
|
{
|
||||||
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtSecretKey));
|
||||||
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||||
|
|
||||||
|
var claims = new[]
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.Username),
|
||||||
|
new Claim("username", user.Username)
|
||||||
|
};
|
||||||
|
|
||||||
|
var token = new JwtSecurityToken(
|
||||||
|
issuer: "taxbaik-admin",
|
||||||
|
audience: "taxbaik-admin-client",
|
||||||
|
claims: claims,
|
||||||
|
expires: DateTime.UtcNow.AddMinutes(_tokenExpirationMinutes),
|
||||||
|
signingCredentials: creds);
|
||||||
|
|
||||||
|
return new JwtSecurityTokenHandler().WriteToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClaimsPrincipal? ValidateToken(string token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtSecretKey));
|
||||||
|
var handler = new JwtSecurityTokenHandler();
|
||||||
|
var principal = handler.ValidateToken(token, new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
IssuerSigningKey = key,
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidIssuer = "taxbaik-admin",
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidAudience = "taxbaik-admin-client",
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ClockSkew = TimeSpan.Zero
|
||||||
|
}, out SecurityToken validatedToken);
|
||||||
|
|
||||||
|
return principal;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
|
||||||
|
namespace TaxBaik.Admin.Services;
|
||||||
|
|
||||||
|
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
||||||
|
{
|
||||||
|
private readonly ILocalStorageService _localStorage;
|
||||||
|
private readonly AuthService _authService;
|
||||||
|
private readonly ILogger<CustomAuthenticationStateProvider> _logger;
|
||||||
|
|
||||||
|
public CustomAuthenticationStateProvider(ILocalStorageService localStorage, AuthService authService, ILogger<CustomAuthenticationStateProvider> logger)
|
||||||
|
{
|
||||||
|
_localStorage = localStorage;
|
||||||
|
_authService = authService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var token = await _localStorage.GetItemAsStringAsync("auth_token");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(token))
|
||||||
|
{
|
||||||
|
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsTokenExpired(token))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("토큰 만료됨");
|
||||||
|
await _localStorage.RemoveItemAsync("auth_token");
|
||||||
|
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
var principal = _authService.ValidateToken(token);
|
||||||
|
if (principal == null)
|
||||||
|
{
|
||||||
|
await _localStorage.RemoveItemAsync("auth_token");
|
||||||
|
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AuthenticationState(principal);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "인증 상태 조회 중 오류 발생");
|
||||||
|
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LoginAsync(string token)
|
||||||
|
{
|
||||||
|
await _localStorage.SetItemAsStringAsync("auth_token", token);
|
||||||
|
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogoutAsync()
|
||||||
|
{
|
||||||
|
await _localStorage.RemoveItemAsync("auth_token");
|
||||||
|
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsTokenExpired(string token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var handler = new JwtSecurityTokenHandler();
|
||||||
|
var jwtToken = handler.ReadJwtToken(token);
|
||||||
|
return jwtToken.ValidTo < DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace TaxBaik.Admin.Services;
|
||||||
|
|
||||||
|
public interface ILocalStorageService
|
||||||
|
{
|
||||||
|
Task<string?> GetItemAsStringAsync(string key);
|
||||||
|
Task SetItemAsStringAsync(string key, string value);
|
||||||
|
Task RemoveItemAsync(string key);
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.JSInterop;
|
||||||
|
|
||||||
|
namespace TaxBaik.Admin.Services;
|
||||||
|
|
||||||
|
public class LocalStorageService : ILocalStorageService
|
||||||
|
{
|
||||||
|
private readonly IJSRuntime _jsRuntime;
|
||||||
|
|
||||||
|
public LocalStorageService(IJSRuntime jsRuntime)
|
||||||
|
{
|
||||||
|
_jsRuntime = jsRuntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string?> GetItemAsStringAsync(string key)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _jsRuntime.InvokeAsync<string>("localStorage.getItem", key);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SetItemAsStringAsync(string key, string value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, value);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveItemAsync(string key)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,26 @@
|
|||||||
<div class="top-row ps-3 navbar navbar-dark">
|
@using System.Security.Claims
|
||||||
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
|
@using TaxBaik.Admin.Services
|
||||||
|
@inject AuthenticationStateProvider AuthStateProvider
|
||||||
|
@inject CustomAuthenticationStateProvider CustomAuthStateProvider
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
|
<div class="top-row ps-3 navbar navbar-dark">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="">TaxBaik.Admin</a>
|
<a class="navbar-brand" href="">TaxBaik.Admin</a>
|
||||||
|
<div class="d-flex align-items-center gap-3 ms-auto">
|
||||||
|
<AuthorizeView>
|
||||||
|
<Authorized>
|
||||||
|
<div class="user-info text-light">
|
||||||
|
<span>@context.User.FindFirst(ClaimTypes.Name)?.Value</span>
|
||||||
|
<button class="btn btn-sm btn-outline-light ms-2" @onclick="HandleLogout">로그아웃</button>
|
||||||
|
</div>
|
||||||
|
</Authorized>
|
||||||
|
<NotAuthorized>
|
||||||
|
<a href="login" class="btn btn-sm btn-outline-light">로그인</a>
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
|
</div>
|
||||||
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
|
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
@@ -10,18 +30,18 @@
|
|||||||
<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
|
<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
|
||||||
<nav class="flex-column">
|
<nav class="flex-column">
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="dashboard" Match="NavLinkMatch.All">
|
||||||
<span class="oi oi-home" aria-hidden="true"></span> Home
|
<span class="oi oi-home" aria-hidden="true"></span> 대시보드
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="counter">
|
<NavLink class="nav-link" href="blog">
|
||||||
<span class="oi oi-plus" aria-hidden="true"></span> Counter
|
<span class="oi oi-document" aria-hidden="true"></span> 블로그
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="fetchdata">
|
<NavLink class="nav-link" href="inquiries">
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
|
<span class="oi oi-envelope-closed" aria-hidden="true"></span> 문의사항
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -36,4 +56,10 @@
|
|||||||
{
|
{
|
||||||
collapseNavMenu = !collapseNavMenu;
|
collapseNavMenu = !collapseNavMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task HandleLogout()
|
||||||
|
{
|
||||||
|
await CustomAuthStateProvider.LogoutAsync();
|
||||||
|
NavigationManager.NavigateTo("/login", forceLoad: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MudBlazor" Version="6.9.4" />
|
<PackageReference Include="MudBlazor" Version="6.9.4" />
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
|
||||||
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -8,3 +8,4 @@
|
|||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using TaxBaik.Admin
|
@using TaxBaik.Admin
|
||||||
@using TaxBaik.Admin.Shared
|
@using TaxBaik.Admin.Shared
|
||||||
|
@using TaxBaik.Admin.Services
|
||||||
|
|||||||
@@ -5,5 +5,11 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"Default": "Host=localhost;Database=taxbaikdb;Username=taxbaik;Password=password123"
|
||||||
|
},
|
||||||
|
"Jwt": {
|
||||||
|
"SecretKey": "dev-secret-key-change-in-production-min-32-chars!"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public static class DependencyInjection
|
|||||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IDbConnectionFactory, DbConnectionFactory>();
|
services.AddSingleton<IDbConnectionFactory, DbConnectionFactory>();
|
||||||
|
services.AddScoped<IAdminUserRepository, AdminUserRepository>();
|
||||||
services.AddScoped<ICategoryRepository, CategoryRepository>();
|
services.AddScoped<ICategoryRepository, CategoryRepository>();
|
||||||
services.AddScoped<IBlogPostRepository, BlogPostRepository>();
|
services.AddScoped<IBlogPostRepository, BlogPostRepository>();
|
||||||
services.AddScoped<IInquiryRepository, InquiryRepository>();
|
services.AddScoped<IInquiryRepository, InquiryRepository>();
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public class BlogIndexModel : PageModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnGetAsync(int page = 1, int? categoryId = null)
|
public async Task OnGetAsync(int page = 1, int? categoryId = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
CurrentPage = page;
|
CurrentPage = page;
|
||||||
SelectedCategoryId = categoryId;
|
SelectedCategoryId = categoryId;
|
||||||
@@ -32,4 +34,14 @@ public class BlogIndexModel : PageModel
|
|||||||
Posts = posts.ToList();
|
Posts = posts.ToList();
|
||||||
TotalPages = (total + PageSize - 1) / PageSize;
|
TotalPages = (total + PageSize - 1) / PageSize;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// DB 연결 실패 시 빈 리스트로 처리
|
||||||
|
CurrentPage = page;
|
||||||
|
SelectedCategoryId = categoryId;
|
||||||
|
Categories = new List<Category>();
|
||||||
|
Posts = new List<BlogPost>();
|
||||||
|
TotalPages = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,5 +50,12 @@ public class ContactModel : PageModel
|
|||||||
ModelState.AddModelError("", ex.Message);
|
ModelState.AddModelError("", ex.Message);
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// DB 연결 실패 등의 경우에도 사용자에게 성공 메시지 표시
|
||||||
|
// 실제 환경에서는 별도의 로깅 및 이메일 알림 필요
|
||||||
|
ModelState.AddModelError("", "시스템 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,16 @@ public class IndexModel : PageModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnGetAsync()
|
public async Task OnGetAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var (posts, _) = await _blogService.GetPublishedPagedAsync(1, 3);
|
var (posts, _) = await _blogService.GetPublishedPagedAsync(1, 3);
|
||||||
RecentPosts = posts.ToList();
|
RecentPosts = posts.ToList();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// DB 연결 실패 시 빈 리스트로 처리
|
||||||
|
RecentPosts = new List<BlogPost>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ builder.Services.AddSingleton(versionInfo);
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Run migrations on startup
|
// Run migrations on startup (non-blocking for development)
|
||||||
|
try
|
||||||
|
{
|
||||||
using (var scope = app.Services.CreateScope())
|
using (var scope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var connectionFactory = scope.ServiceProvider.GetRequiredService<TaxBaik.Domain.Interfaces.IDbConnectionFactory>();
|
var connectionFactory = scope.ServiceProvider.GetRequiredService<TaxBaik.Domain.Interfaces.IDbConnectionFactory>();
|
||||||
@@ -46,6 +48,11 @@ using (var scope = app.Services.CreateScope())
|
|||||||
var migrationRunner = new TaxBaik.Infrastructure.Data.MigrationRunner(cs, connectionFactory);
|
var migrationRunner = new TaxBaik.Infrastructure.Data.MigrationRunner(cs, connectionFactory);
|
||||||
await migrationRunner.RunAsync();
|
await migrationRunner.RunAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"⚠️ Migration warning (non-blocking): {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
app.UsePathBase("/taxbaik");
|
app.UsePathBase("/taxbaik");
|
||||||
app.UseResponseCompression();
|
app.UseResponseCompression();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "http://localhost:5012",
|
"applicationUrl": "http://localhost:5001",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:7012;http://localhost:5012",
|
"applicationUrl": "https://localhost:7001;http://localhost:5001",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user