Files
taxbaik/TaxBaik.Admin/Components/Pages/Login.razor
T
kjh2064 dc9aa108a1
TaxBaik CI/CD / build-and-deploy (push) Failing after 16s
작업중: W4 관리자 로그인 구현 (BCrypt 인증)
- Login.razor: BCrypt 기반 실제 비밀번호 검증
- TaxBaik.Admin.csproj: BCrypt.Net-Next 패키지 추가
- HttpContext.SignInAsync로 쿠키 인증 처리

주의: 아직 런타임 이슈 수정 필요

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-26 17:00:03 +09:00

99 lines
3.3 KiB
Plaintext

@page "/login"
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@layout TaxBaik.Admin.Components.Layout.BlankLayout
@attribute [AllowAnonymous]
<PageTitle>로그인</PageTitle>
<MudContainer MaxWidth="MaxWidth.Small" Class="d-flex align-center justify-center" Style="min-height: 100vh;">
<MudPaper Class="pa-8" Elevation="3" Style="width: 100%; max-width: 400px;">
<MudText Typo="Typo.h4" Class="mb-6 text-center">관리자 로그인</MudText>
<MudForm @ref="form" @bind-IsValid="@isFormValid">
<MudTextField @bind-Value="model.Username" Label="사용자명"
Variant="Variant.Outlined" Required="true" Class="mb-4" />
<MudTextField @bind-Value="model.Password" Label="비밀번호" InputType="InputType.Password"
Variant="Variant.Outlined" Required="true" Class="mb-4" />
@if (!string.IsNullOrEmpty(errorMessage))
{
<MudAlert Severity="Severity.Error" Class="mb-4">@errorMessage</MudAlert>
}
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
Size="Size.Large" OnClick="HandleLogin">로그인</MudButton>
</MudForm>
</MudPaper>
</MudContainer>
@using Microsoft.AspNetCore.Authentication
@using System.Security.Claims
@using TaxBaik.Domain.Interfaces
@code {
private MudForm form;
private bool isFormValid = false;
private string errorMessage = "";
private LoginModel model = new();
private bool isLoading = false;
[Inject]
private IAdminUserRepository AdminUserRepository { get; set; }
[Inject]
private NavigationManager NavigationManager { get; set; }
[Inject]
private HttpContextAccessor HttpContextAccessor { get; set; }
private async Task HandleLogin()
{
if (!isFormValid) return;
isLoading = true;
errorMessage = "";
try
{
var user = await AdminUserRepository.GetByUsernameAsync(model.Username);
if (user == null || !BCrypt.Net.BCrypt.Verify(model.Password, user.PasswordHash))
{
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
isLoading = false;
return;
}
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
new Claim(ClaimTypes.Name, user.Username)
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties { IsPersistent = true };
await HttpContextAccessor.HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
NavigationManager.NavigateTo("/taxbaik/admin/dashboard");
}
catch (Exception ex)
{
errorMessage = $"로그인 중 오류: {ex.Message}";
}
finally
{
isLoading = false;
}
}
private class LoginModel
{
public string Username { get; set; }
public string Password { get; set; }
}
}