73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using ChronoFlow.Model;
|
|
|
|
namespace ChronoFlow.View.Security;
|
|
|
|
/// <summary>
|
|
/// Dialog zum Ändern des Passworts eines Benutzers.
|
|
/// </summary>
|
|
public partial class PasswortAendernDialog : Window
|
|
{
|
|
/// <summary>
|
|
/// Das neue Passwort, das im Dialog eingegeben wurde.
|
|
/// </summary>
|
|
public string NeuesPasswort { get; private set; } = "";
|
|
|
|
private readonly User _user;
|
|
|
|
/// <summary>
|
|
/// Parameterloser Konstruktor für Avalonia (z.B. für Preview, AVLN:0005-Fix).
|
|
/// ⚠ Wird nur für Entwicklungszwecke oder Design-Time genutzt.
|
|
/// </summary>
|
|
public PasswortAendernDialog() : this(new User { Username = "DemoUser", Role = "Mitarbeiter" })
|
|
{
|
|
System.Console.WriteLine("⚠ Parameterloser Konstruktor für PasswortAendernDialog verwendet.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Konstruktor mit Benutzerobjekt (wird im echten Ablauf verwendet).
|
|
/// </summary>
|
|
/// <param name="user">Der aktuell eingeloggte Benutzer.</param>
|
|
public PasswortAendernDialog(User user)
|
|
{
|
|
InitializeComponent();
|
|
_user = user;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Wird aufgerufen, wenn der Benutzer auf "Speichern" klickt.
|
|
/// Prüft Eingaben und schließt den Dialog mit dem neuen Passwort.
|
|
/// </summary>
|
|
private void SpeichernButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
var passwort = NeuesPasswortBox.Text?.Trim();
|
|
var bestaetigen = BestaetigenBox.Text?.Trim();
|
|
|
|
if (string.IsNullOrWhiteSpace(passwort) || string.IsNullOrWhiteSpace(bestaetigen))
|
|
{
|
|
FehlerText.Text = "Bitte alle Felder ausfüllen.";
|
|
FehlerText.IsVisible = true;
|
|
return;
|
|
}
|
|
|
|
if (passwort != bestaetigen)
|
|
{
|
|
FehlerText.Text = "Passwörter stimmen nicht überein.";
|
|
FehlerText.IsVisible = true;
|
|
return;
|
|
}
|
|
|
|
NeuesPasswort = passwort;
|
|
Close(NeuesPasswort);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bricht den Vorgang ab und schließt den Dialog ohne Ergebnis.
|
|
/// </summary>
|
|
private void AbbrechenButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
Close(null);
|
|
}
|
|
}
|