Files
secdevops-csharp-app/Components/Pages/Login.razor
Achim H. 0fb95e78f7
All checks were successful
Tests / Declarative: Post Actions No test results found
csharp-secdevops-pipeline-pod/pipeline/head This commit looks good
changed login form
2026-06-11 11:05:42 +02:00

41 lines
1.3 KiB
Plaintext

@page "/login"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@inject NavigationManager Navigation
<h3>SecDevOps Lab Login</h3>
@if (!string.IsNullOrEmpty(errorMessage))
{
<div class="alert alert-danger">@errorMessage</div>
}
@* Wichtig: Ein traditionelles HTML-Formular nutzen, um Cookies setzen zu können *@
<form action="/api/auth/login" method="post">
<AntiforgeryToken />
<div class="mb-3">
<label class="form-label">Benutzername</label>
<input type="text" name="username" class="form-control" required />
</div>
<div class="mb-3">
<label class="form-label">Passwort</label>
<input type="password" name="password" class="form-control" required />
</div>
<button type="submit" class="btn btn-primary">Einloggen</button>
</form>
@code {
private string? errorMessage;
protected override void OnInitialized()
{
// Falls ein Fehler beim Login auftrat, fangen wir ihn über die URL ab
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("error", out var error))
{
errorMessage = "Ungültige Zugangsdaten.";
}
}
}