Settings Page erstellt

This commit is contained in:
Daniel Habenicht
2025-06-20 14:09:56 +02:00
parent 8bf1df3ba4
commit 3d496970ac
8 changed files with 67 additions and 10 deletions

View File

@@ -133,4 +133,46 @@ public class AuthController : Controller
return RedirectToAction("Index", "Home");
}
// Edit-Form anzeigen
[Authorize]
[HttpGet]
public IActionResult UserSettings()
{
var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username);
if (user == null) return NotFound();
var model = new EditUserViewModel
{
Username = user.PreferredUsername
};
return View(model);
}
// Edit speichern
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult UserSettings(EditUserViewModel model)
{
if (!ModelState.IsValid) return View(model);
var username = User.Identity?.Name;
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username);
if (user == null) return NotFound();
user.PreferredUsername = model.Username;
if (!string.IsNullOrWhiteSpace(model.NewPassword))
{
user.PreferredUsername = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
}
_context.SaveChanges();
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert
return RedirectToAction("Index", "Home");
}
}

View File

@@ -19,7 +19,10 @@
<span>@(User.Identity?.Name?.Substring(0,1).ToUpper() ?? "?")</span>
</div>
}
<h3 class="mt-3"><i class="bi bi-person-circle me-1"></i>@(User.FindFirst("name")?.Value ?? "Unbekannter Nutzer")</h3>
<h3 class="mt-3">
<i class="bi bi-person-circle me-1"></i>@(User.FindFirst("name")?.Value ?? "Unbekannter Nutzer")
</h3>
</div>
<table class="table table-hover">
@@ -75,12 +78,18 @@
</tr>
</tbody>
</table>
<form method="post" asp-controller="Auth" asp-action="Logout" class="text-center mt-4">
<button type="submit" class="btn btn-danger">
<i class="bi bi-box-arrow-right me-1"></i>Abmelden
</button>
</form>
<div>
<form method="get" asp-controller="Auth" asp-action="UserSettings" class="text-center mt-4">
<button type="submit" class="btn btn-info">
<i class="bi bi-gear-wide-connected me-1"></i>Einstellungen
</button>
</form>
<form method="post" asp-controller="Auth" asp-action="Logout" class="text-center mt-4">
<button type="submit" class="btn btn-danger">
<i class="bi bi-box-arrow-right me-1"></i>Abmelden
</button>
</form>
</div>
</div>
@if (isAdmin)

View File

@@ -0,0 +1 @@
<h1>settings</h1>

View File

@@ -16,7 +16,7 @@
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
@foreach (var s in Model.Servers)
{
<div class="bg-white rounded-xl shadow p-5 border border-gray-200 flex flex-col gap-4">
<div class="bg-blue rounded-xl shadow p-5 border border-gray-200 flex flex-col gap-4">
<div class="flex justify-between items-center">
<h2 class="text-lg font-semibold text-gray-800">
<i class="bi bi-cpu me-1 text-gray-600"></i>(#@s.Id) @s.Name
@@ -133,5 +133,4 @@
}
});
</script>
}
}

View File

@@ -1,6 +1,11 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
html, body {
min-height: 100vh;
overflow-y: auto;
}
a.navbar-brand {
white-space: normal;
text-align: center;

Binary file not shown.

View File

@@ -0,0 +1 @@