a039bb53a4
- AuthService로 JWT 토큰 생성 및 검증 - CustomAuthenticationStateProvider를 통한 Blazor 인증 통합 - LocalStorageService로 토큰 관리 - Login.razor 완전 재작성 (실제 DB 검증, 토큰 발급) - BCrypt 기반 비밀번호 검증 - admin/admin123으로 테스트 가능 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
86 lines
2.8 KiB
Plaintext
86 lines
2.8 KiB
Plaintext
@page "/login"
|
|
@using System.ComponentModel.DataAnnotations
|
|
@layout TaxBaik.Admin.Components.Layout.BlankLayout
|
|
@attribute [AllowAnonymous]
|
|
@inject AuthService AuthService
|
|
@inject NavigationManager NavigationManager
|
|
@inject CustomAuthenticationStateProvider AuthStateProvider
|
|
|
|
<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" Disabled="isLoading">
|
|
@if (isLoading)
|
|
{
|
|
<MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
|
|
<span>로그인 중...</span>
|
|
}
|
|
else
|
|
{
|
|
<span>로그인</span>
|
|
}
|
|
</MudButton>
|
|
</MudForm>
|
|
</MudPaper>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private MudForm form;
|
|
private bool isFormValid = false;
|
|
private bool isLoading = false;
|
|
private string errorMessage = "";
|
|
|
|
private LoginModel model = new();
|
|
|
|
private async Task HandleLogin()
|
|
{
|
|
if (isLoading)
|
|
return;
|
|
|
|
isLoading = true;
|
|
errorMessage = "";
|
|
|
|
try
|
|
{
|
|
var token = await AuthService.AuthenticateAndGenerateTokenAsync(model.Username, model.Password);
|
|
|
|
if (token == null)
|
|
{
|
|
errorMessage = "사용자명 또는 비밀번호가 올바르지 않습니다.";
|
|
isLoading = false;
|
|
return;
|
|
}
|
|
|
|
await AuthStateProvider.LoginAsync(token);
|
|
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", forceLoad: false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = "로그인 중 오류가 발생했습니다.";
|
|
isLoading = false;
|
|
}
|
|
}
|
|
|
|
private class LoginModel
|
|
{
|
|
public string Username { get; set; } = "";
|
|
public string Password { get; set; } = "";
|
|
}
|
|
}
|