71 lines
2.0 KiB
Plaintext
71 lines
2.0 KiB
Plaintext
@page "/login"
|
|
@layout AuthLayout
|
|
@using Microsoft.AspNetCore.Identity
|
|
@inject SignInManager<ApplicationUser> SignInManager
|
|
@inject NavigationManager Navigation
|
|
|
|
<PageTitle>Budgeteer — Sign In</PageTitle>
|
|
|
|
<h3 class="text-center mb-4">Sign In</h3>
|
|
|
|
<EditForm Model="Model" OnValidSubmit="HandleLogin" FormName="login">
|
|
<DataAnnotationsValidator />
|
|
|
|
@if (!string.IsNullOrEmpty(errorMessage))
|
|
{
|
|
<div class="alert alert-danger">@errorMessage</div>
|
|
}
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Email</label>
|
|
<InputText @bind-Value="Model.Email" class="form-control" placeholder="you@example.com" />
|
|
<ValidationMessage For="() => Model.Email" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Password</label>
|
|
<InputText @bind-Value="Model.Password" type="password" class="form-control" />
|
|
<ValidationMessage For="() => Model.Password" />
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary w-100">Sign In</button>
|
|
</EditForm>
|
|
|
|
<p class="text-center mt-3">
|
|
Don't have an account? <a href="/register">Register</a>
|
|
</p>
|
|
|
|
@code {
|
|
[SupplyParameterFromForm]
|
|
private LoginModel Model { get; set; } = new();
|
|
|
|
private string? errorMessage;
|
|
|
|
private async Task HandleLogin()
|
|
{
|
|
errorMessage = null;
|
|
|
|
var result = await SignInManager.PasswordSignInAsync(
|
|
Model.Email, Model.Password, isPersistent: false, lockoutOnFailure: false);
|
|
|
|
if (result.Succeeded)
|
|
{
|
|
Navigation.NavigateTo("/", forceLoad: true);
|
|
}
|
|
else
|
|
{
|
|
errorMessage = "Invalid email or password.";
|
|
}
|
|
}
|
|
|
|
private sealed class LoginModel
|
|
{
|
|
[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "Email is required")]
|
|
[System.ComponentModel.DataAnnotations.EmailAddress]
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "Password is required")]
|
|
public string Password { get; set; } = string.Empty;
|
|
}
|
|
}
|