2026-03-16 21:54:44 +01:00
|
|
|
@page "/login"
|
|
|
|
|
@attribute [AllowAnonymous]
|
|
|
|
|
|
|
|
|
|
@using Microsoft.AspNetCore.Authorization
|
|
|
|
|
@using Microsoft.AspNetCore.Components
|
2026-04-20 14:11:18 +02:00
|
|
|
@using Microsoft.Extensions.Options
|
|
|
|
|
@using WorkTracker.Configuration
|
|
|
|
|
|
|
|
|
|
@inject IOptions<AppAuthOptions> AppAuthOptions
|
|
|
|
|
@inject NavigationManager Navigation
|
2026-03-16 21:54:44 +01:00
|
|
|
|
|
|
|
|
<PageTitle>Login</PageTitle>
|
|
|
|
|
|
2026-04-20 14:11:18 +02:00
|
|
|
@if (!AppAuthOptions.Value.Enabled)
|
|
|
|
|
{
|
|
|
|
|
<p>Redirecting...</p>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-03-16 21:54:44 +01:00
|
|
|
<h1>Login</h1>
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrWhiteSpace(Error))
|
|
|
|
|
{
|
|
|
|
|
<div class="alert alert-danger" role="alert">@Error</div>
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 20:08:02 +01:00
|
|
|
<form method="post" action="/api/login" class="d-flex flex-column gap-3" style="max-width: 420px;">
|
2026-03-16 21:54:44 +01:00
|
|
|
<div>
|
2026-03-17 20:08:02 +01:00
|
|
|
<label for="username" class="form-label">Username</label>
|
|
|
|
|
<input id="username" name="username" value="@Username" autocomplete="username" class="form-control" required />
|
2026-03-16 21:54:44 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<label for="password" class="form-label">Password</label>
|
|
|
|
|
<input id="password" name="password" type="password" autocomplete="current-password" class="form-control" required />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<input type="hidden" name="returnUrl" value="@SafeReturnUrl" />
|
|
|
|
|
|
|
|
|
|
<button type="submit" class="btn btn-primary">Sign in</button>
|
|
|
|
|
</form>
|
2026-04-20 14:11:18 +02:00
|
|
|
}
|
2026-03-16 21:54:44 +01:00
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[SupplyParameterFromQuery]
|
|
|
|
|
public string? ReturnUrl { get; set; }
|
|
|
|
|
|
|
|
|
|
[SupplyParameterFromQuery]
|
|
|
|
|
public string? Error { get; set; }
|
|
|
|
|
|
|
|
|
|
[SupplyParameterFromQuery]
|
2026-03-17 20:08:02 +01:00
|
|
|
public string? Username { get; set; }
|
2026-03-16 21:54:44 +01:00
|
|
|
|
2026-04-20 14:11:18 +02:00
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
if (!AppAuthOptions.Value.Enabled)
|
|
|
|
|
{
|
|
|
|
|
Navigation.NavigateTo(SafeReturnUrl, forceLoad: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 21:54:44 +01:00
|
|
|
private string SafeReturnUrl =>
|
|
|
|
|
string.IsNullOrWhiteSpace(ReturnUrl) || !Uri.IsWellFormedUriString(ReturnUrl, UriKind.Relative)
|
|
|
|
|
? "/"
|
|
|
|
|
: ReturnUrl;
|
|
|
|
|
}
|