36 lines
840 B
Plaintext
36 lines
840 B
Plaintext
@page "/login"
|
|
@inject AccountsClient Accounts
|
|
@inject NotificationManager Notifications
|
|
@inject NavigationManager Navigation
|
|
@inject AuthenticationStateProvider AuthStateProvider
|
|
|
|
<Title Value="Sign in!" />
|
|
|
|
<EditForm Model="@_model" OnValidSubmit="TryLogin">
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
|
|
<InputText @bind-Value="_model.Username" />
|
|
<InputText type="password" @bind-Value="_model.Password" />
|
|
|
|
<button type="submit">Log in!</button>
|
|
</EditForm>
|
|
|
|
@code
|
|
{
|
|
private LoginViewModel _model = new LoginViewModel();
|
|
|
|
private async Task TryLogin()
|
|
{
|
|
try
|
|
{
|
|
var token = await Accounts.LoginAsync(_model);
|
|
((CustomAuthStateProvider)AuthStateProvider).MarkUserAsAuthenticated(token);
|
|
Navigation.NavigateTo("/");
|
|
}
|
|
catch
|
|
{
|
|
Notifications.Add("login failed!");
|
|
}
|
|
}
|
|
} |