Merge pull request 'enhancement/ui-upgrade' (#27) from enhancement/ui-upgrade into development
Reviewed-on: daniel-hbn/Watcher#27
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Watcher.Data;
|
||||
using Watcher.ViewModels;
|
||||
|
||||
@@ -122,6 +124,56 @@ public class AuthController : Controller
|
||||
|
||||
user.PreferredUsername = model.Username;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.NewPassword))
|
||||
{
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
// Edit-Form anzeigen
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public IActionResult UserSettings()
|
||||
{
|
||||
var username = User.Identity?.Name;
|
||||
var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList();
|
||||
|
||||
var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
var DbProvider = _context.Database.ProviderName;
|
||||
|
||||
ViewBag.Name = username;
|
||||
ViewBag.Claims = claims;
|
||||
ViewBag.IdentityProvider = user.IdentityProvider;
|
||||
ViewBag.DbProvider = DbProvider;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
var databaseProvider = _context.Database.ProviderName;
|
||||
|
||||
user.PreferredUsername = model.Username;
|
||||
|
||||
// Passwort ändern
|
||||
if (!string.IsNullOrWhiteSpace(model.NewPassword))
|
||||
{
|
||||
user.PreferredUsername = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
|
||||
|
18
Watcher/ViewModels/EditUserSettingsViewModel.cs
Normal file
18
Watcher/ViewModels/EditUserSettingsViewModel.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Watcher.ViewModels;
|
||||
|
||||
public class EditUserSettingsViewModel
|
||||
{
|
||||
[Required]
|
||||
public string? Username { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string? NewPassword { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
[Compare("NewPassword", ErrorMessage = "Passwörter stimmen nicht überein.")]
|
||||
public string? ConfirmPassword { get; set; }
|
||||
}
|
@@ -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,41 +78,17 @@
|
||||
</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>
|
||||
|
||||
@if (isAdmin)
|
||||
{
|
||||
<div class="card shadow mt-5 p-4" style="max-width: 700px; margin: auto;">
|
||||
<h4><i class="bi bi-pencil-square me-2"></i>Benutzerdaten ändern</h4>
|
||||
<form asp-action="Edit" method="post" asp-controller="Auth">
|
||||
<div class="mb-3">
|
||||
<label for="Username" class="form-label">Neuer Benutzername</label>
|
||||
<input type="text" class="form-control" id="Username" name="Username" value="@preferredUsername" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="NewPassword" class="form-label">Neues Passwort</label>
|
||||
<input type="password" class="form-control" id="NewPassword" name="NewPassword" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ConfirmPassword" class="form-label">Passwort bestätigen</label>
|
||||
<input type="password" class="form-control" id="ConfirmPassword" name="ConfirmPassword" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-save me-1"></i>Speichern
|
||||
<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>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="alert alert-info mt-4 text-center" style="max-width: 700px; margin: auto;">
|
||||
<i class="bi bi-info-circle me-1"></i>Benutzerdaten können nur für lokal angemeldete Nutzer geändert werden.
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
92
Watcher/Views/Auth/UserSettings.cshtml
Normal file
92
Watcher/Views/Auth/UserSettings.cshtml
Normal file
@@ -0,0 +1,92 @@
|
||||
@{
|
||||
ViewData["Title"] = "Settings";
|
||||
var pictureUrl = User.Claims.FirstOrDefault(c => c.Type == "picture")?.Value ?? "";
|
||||
var preferredUsername = User.Claims.FirstOrDefault(c => c.Type == "preferred_username")?.Value ?? "admin";
|
||||
var isLocalUser = ViewBag.IdentityProvider == "local";
|
||||
var DbEngine = ViewBag.DbProvider;
|
||||
}
|
||||
|
||||
<style>
|
||||
.Settingscontainer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
/* Wichtig: erlaubt Umbruch */
|
||||
gap: 1rem;
|
||||
/* optionaler Abstand */
|
||||
}
|
||||
|
||||
.Settingscontainer>* {
|
||||
flex: 1 1 calc(50% - 0.5rem);
|
||||
/* 2 Elemente pro Zeile, inkl. Gap */
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="Settingscontainer">
|
||||
@if (isLocalUser)
|
||||
{
|
||||
<div class="card shadow mt-5 p-4" style="width: 40%; margin: auto;">
|
||||
<h4><i class="bi bi-pencil-square me-2"></i>Benutzerdaten ändern</h4>
|
||||
<form asp-action="Edit" method="post" asp-controller="Auth">
|
||||
<div class="mb-3">
|
||||
<label for="Username" class="form-label">Neuer Benutzername</label>
|
||||
<input type="text" class="form-control" id="Username" name="Username" value="@preferredUsername" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="NewPassword" class="form-label">Neues Passwort</label>
|
||||
<input type="password" class="form-control" id="NewPassword" name="NewPassword" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ConfirmPassword" class="form-label">Passwort bestätigen</label>
|
||||
<input type="password" class="form-control" id="ConfirmPassword" name="ConfirmPassword" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-save me-1"></i>Speichern
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="alert alert-info mt-4 text-center" style="width: 40%; margin: auto;">
|
||||
<i class="bi bi-info-circle me-1"></i>Benutzerdaten können nur für lokal angemeldete Nutzer geändert werden.
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<div class="card shadow mt-5 p-4" style="width: 55%; margin: auto;">
|
||||
<h4><i class="bi bi-pencil-square me-2"></i>Systemeinformationen</h4>
|
||||
|
||||
<br>
|
||||
|
||||
<h5>Watcher Version: v0.1.0</h5>
|
||||
|
||||
<hr class="my-4" />
|
||||
|
||||
<h5>Authentifizierungsmethode: </h5>
|
||||
<p><strong>@(ViewBag.IdentityProvider ?? "nicht gefunden")</strong></p>
|
||||
|
||||
<hr class="my-4" />
|
||||
|
||||
<h5>Datenbank-Engine: </h5>
|
||||
<strong>@(DbEngine ?? "nicht gefunden")</strong>
|
||||
<form method="get" asp-controller="Auth" asp-action="DbExport" class="text-center mt-4">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-gear-wide-connected me-1"></i>Datenbank exportieren
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card shadow mt-5 p-4" style="width: 55%; margin: auto;">
|
||||
<h4><i class="bi bi-pencil-square me-2"></i>Systemeinstellungen ändern</h4>
|
||||
|
||||
<h5>Anzeigeeinstellungen: </h5>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
@@ -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>
|
||||
}
|
||||
|
||||
}
|
@@ -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.
@@ -0,0 +1 @@
|
||||
|
||||
|
Reference in New Issue
Block a user