Replace MSAL and custom cookie auth with Microsoft.Identity.EntityFramework Also some UI redesign to accommodate different login experience.
72 lines
1.6 KiB
Plaintext
72 lines
1.6 KiB
Plaintext
@page "/login"
|
|
@inject IAccountManagement Acct
|
|
@inject NavigationManager navigator
|
|
|
|
<main class="PrimaryTheme">
|
|
<h1>Login</h1>
|
|
|
|
<section class="LoginForm">
|
|
<AuthorizeView>
|
|
<Authorized>
|
|
<div>You're logged in as @context.User.Identity?.Name.</div>
|
|
</Authorized>
|
|
<NotAuthorized>
|
|
@if (errorList.Length > 0)
|
|
{
|
|
<ul class="Errors" style="grid-area: errors">
|
|
@foreach (var error in errorList)
|
|
{
|
|
<li>@error</li>
|
|
}
|
|
</ul>
|
|
}
|
|
|
|
<label for="email" style="grid-area: emailLabel">Email</label>
|
|
<input required id="email" name="emailInput" type="email" style="grid-area: emailControl" @bind-value="email" />
|
|
|
|
<label for="password" style="grid-area: passLabel">Password</label>
|
|
<input required id="password" name="passwordInput" type="password" style="grid-area: passControl" @bind-value="password" />
|
|
|
|
<button style="grid-area: button" @onclick="DoLoginAsync">Login</button>
|
|
</NotAuthorized>
|
|
</AuthorizeView>
|
|
</section>
|
|
|
|
</main>
|
|
|
|
@code {
|
|
private string email = string.Empty;
|
|
private string password = string.Empty;
|
|
private string[] errorList = [];
|
|
|
|
public async Task DoLoginAsync()
|
|
{
|
|
errorList = [];
|
|
|
|
if (string.IsNullOrWhiteSpace(email))
|
|
{
|
|
errorList = ["Email is required."];
|
|
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
|
{
|
|
errorList = ["Password is required."];
|
|
|
|
return;
|
|
}
|
|
|
|
var result = await Acct.LoginAsync(email, password);
|
|
|
|
if (result.Succeeded)
|
|
{
|
|
email = password = string.Empty;
|
|
navigator.NavigateTo("/");
|
|
}
|
|
else
|
|
{
|
|
errorList = result.ErrorList;
|
|
}
|
|
}
|
|
} |