You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.6 KiB
43 lines
1.6 KiB
@page "/login"
|
|
@inject IToastService ToastService
|
|
@rendermode RenderMode.InteractiveServer
|
|
|
|
<FluentGrid Justify="JustifyContent.Center">
|
|
<FluentGridItem sm="4">
|
|
<h2>Login</h2>
|
|
<FluentEditForm Model="@login" OnValidSubmit="@OnLoginSubmit">
|
|
<DataAnnotationsValidator/>
|
|
<FluentValidationSummary/>
|
|
|
|
<FluentStack Orientation="Orientation.Vertical" VerticalGap="5">
|
|
<div>
|
|
<FluentTextField @bind-Value="login.Name" Label="Name" Required/>
|
|
<FluentValidationMessage For="@(() => login.Name)"/>
|
|
</div>
|
|
<div>
|
|
<FluentTextField @bind-Value="login.Password" TextFieldType="TextFieldType.Password" Label="Password" Required />
|
|
<FluentValidationMessage For="@(() => login.Password)" />
|
|
</div>
|
|
<FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Login</FluentButton>
|
|
</FluentStack>
|
|
</FluentEditForm>
|
|
</FluentGridItem>
|
|
</FluentGrid>
|
|
|
|
@code {
|
|
LoginDTO login = new LoginDTO();
|
|
|
|
async Task OnLoginSubmit(EditContext context)
|
|
{
|
|
LoginResponse response = await AccountService.LoginAsync(login);
|
|
if (!response.Flag)
|
|
{
|
|
ToastService.ShowError(response.message, 5000);
|
|
return;
|
|
}
|
|
|
|
var customAuthProvider = (CustomAuthenticationStateProvider)AuthStateProvider;
|
|
customAuthProvider.UpdateAuthenticationState(response.JWTToken);
|
|
NavManager.NavigateTo("/", forceLoad: true);
|
|
}
|
|
}
|
|
|