Updated the proostekrant to work properly again.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
@page "/login"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@inject UserService Gebruikers
|
||||
|
||||
<PageTitle>Inloggen — ProostenKrant</PageTitle>
|
||||
|
||||
<section class="card auth-card">
|
||||
<h1 class="headline">Inloggen redactie</h1>
|
||||
<p class="muted">Kies je naam en voer het familiewachtwoord in.</p>
|
||||
|
||||
@if (_fout is not null)
|
||||
{
|
||||
<p class="alert alert-error">@_fout</p>
|
||||
}
|
||||
|
||||
<EditForm FormName="login" Method="post" Model="Input" OnValidSubmit="LoginUser" class="krant-form">
|
||||
<div class="form-group">
|
||||
<label for="username">Familielid</label>
|
||||
<InputSelect @bind-Value="Input.Username" id="username" class="form-control">
|
||||
<option value="">— Kies je naam —</option>
|
||||
@foreach (var gebruiker in _gebruikers)
|
||||
{
|
||||
<option value="@gebruiker.Username">@gebruiker.DisplayName</option>
|
||||
}
|
||||
</InputSelect>
|
||||
<ValidationMessage For="() => Input.Username" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Wachtwoord</label>
|
||||
<InputText type="password" @bind-Value="Input.Password" id="password" class="form-control" autocomplete="current-password" />
|
||||
<ValidationMessage For="() => Input.Password" />
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Inloggen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
[SupplyParameterFromForm(FormName = "login")]
|
||||
private LoginInput Input { get; set; } = new();
|
||||
|
||||
private List<User> _gebruikers = new();
|
||||
private string? _fout;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Input ??= new();
|
||||
_gebruikers = await Gebruikers.GetAllAsync();
|
||||
}
|
||||
|
||||
private async Task LoginUser()
|
||||
{
|
||||
var gebruiker = _gebruikers.FirstOrDefault(g =>
|
||||
string.Equals(g.Username, Input.Username, StringComparison.OrdinalIgnoreCase));
|
||||
if (gebruiker is null || Input.Password != Krant.UniversalPassword)
|
||||
{
|
||||
_fout = "Ongeldige gebruikersnaam of wachtwoord.";
|
||||
return;
|
||||
}
|
||||
|
||||
var principal = KrantAuth.EditorPrincipal(gebruiker);
|
||||
await HttpContext.SignInAsync(KrantAuth.Scheme, principal);
|
||||
Nav.NavigateTo("/dashboard", forceLoad: true);
|
||||
}
|
||||
|
||||
private sealed class LoginInput
|
||||
{
|
||||
[Required(ErrorMessage = "Kies je naam.")]
|
||||
public string Username { get; set; } = "";
|
||||
|
||||
[Required(ErrorMessage = "Voer het wachtwoord in.")]
|
||||
public string Password { get; set; } = "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user