From 7ce89d9fda282d56fcfa9270917e5b72301a51cf Mon Sep 17 00:00:00 2001 From: Daniel Habenicht Date: Fri, 20 Jun 2025 14:30:22 +0200 Subject: [PATCH] EditUserSettingsViewModel --- Watcher/Controllers/AuthController.cs | 3 ++- .../ViewModels/EditUserSettingsViewModel.cs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Watcher/ViewModels/EditUserSettingsViewModel.cs diff --git a/Watcher/Controllers/AuthController.cs b/Watcher/Controllers/AuthController.cs index e18d438..4869c7e 100644 --- a/Watcher/Controllers/AuthController.cs +++ b/Watcher/Controllers/AuthController.cs @@ -143,7 +143,7 @@ public class AuthController : Controller var user = _context.Users.FirstOrDefault(u => u.PreferredUsername == username); if (user == null) return NotFound(); - var model = new EditUserViewModel + var model = new EditUserSettingsViewModel { Username = user.PreferredUsername }; @@ -164,6 +164,7 @@ public class AuthController : Controller user.PreferredUsername = model.Username; + // Passwort ändern if (!string.IsNullOrWhiteSpace(model.NewPassword)) { user.PreferredUsername = BCrypt.Net.BCrypt.HashPassword(model.NewPassword); diff --git a/Watcher/ViewModels/EditUserSettingsViewModel.cs b/Watcher/ViewModels/EditUserSettingsViewModel.cs new file mode 100644 index 0000000..468cc86 --- /dev/null +++ b/Watcher/ViewModels/EditUserSettingsViewModel.cs @@ -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; } +}