WorkTracker/Components/Pages/Login.razor
Marco 08e573d63c
All checks were successful
Publish Container / publish (push) Successful in 5m35s
Removed auth
2026-04-20 14:11:18 +02:00

66 lines
1.7 KiB
Text

@page "/login"
@attribute [AllowAnonymous]
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components
@using Microsoft.Extensions.Options
@using WorkTracker.Configuration
@inject IOptions<AppAuthOptions> AppAuthOptions
@inject NavigationManager Navigation
<PageTitle>Login</PageTitle>
@if (!AppAuthOptions.Value.Enabled)
{
<p>Redirecting...</p>
}
else
{
<h1>Login</h1>
@if (!string.IsNullOrWhiteSpace(Error))
{
<div class="alert alert-danger" role="alert">@Error</div>
}
<form method="post" action="/api/login" class="d-flex flex-column gap-3" style="max-width: 420px;">
<div>
<label for="username" class="form-label">Username</label>
<input id="username" name="username" value="@Username" autocomplete="username" class="form-control" required />
</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>
}
@code {
[SupplyParameterFromQuery]
public string? ReturnUrl { get; set; }
[SupplyParameterFromQuery]
public string? Error { get; set; }
[SupplyParameterFromQuery]
public string? Username { get; set; }
protected override void OnInitialized()
{
if (!AppAuthOptions.Value.Enabled)
{
Navigation.NavigateTo(SafeReturnUrl, forceLoad: true);
}
}
private string SafeReturnUrl =>
string.IsNullOrWhiteSpace(ReturnUrl) || !Uri.IsWellFormedUriString(ReturnUrl, UriKind.Relative)
? "/"
: ReturnUrl;
}