added Login Authentication
This commit is contained in:
39
Components/Pages/Login.razor
Normal file
39
Components/Pages/Login.razor
Normal file
@@ -0,0 +1,39 @@
|
||||
@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">
|
||||
<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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user