更新
This commit is contained in:
69
PetWashControl/Views/AdminLoginWindow.xaml.cs
Normal file
69
PetWashControl/Views/AdminLoginWindow.xaml.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using PetWashControl.Services;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace PetWashControl.Views;
|
||||
|
||||
public partial class AdminLoginWindow : Window
|
||||
{
|
||||
private readonly AdminAccessService _adminAccessService;
|
||||
|
||||
public bool IsAuthenticated { get; private set; }
|
||||
|
||||
public AdminLoginWindow(AdminAccessService adminAccessService)
|
||||
{
|
||||
_adminAccessService = adminAccessService;
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) =>
|
||||
{
|
||||
UsernameTextBox.Focus();
|
||||
ShowMessage(_adminAccessService.GetCurrentLockoutMessage());
|
||||
};
|
||||
}
|
||||
|
||||
private void LoginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var result = _adminAccessService.TryAuthenticate(UsernameTextBox.Text, PasswordInput.Password);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
IsAuthenticated = true;
|
||||
DialogResult = true;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
IsAuthenticated = false;
|
||||
ShowMessage(result.Message);
|
||||
PasswordInput.Clear();
|
||||
PasswordInput.Focus();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DialogResult = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void PasswordInput_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
LoginButton_Click(sender, new RoutedEventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowMessage(string? message)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
ErrorContainer.Visibility = Visibility.Collapsed;
|
||||
ErrorTextBlock.Visibility = Visibility.Collapsed;
|
||||
ErrorTextBlock.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorContainer.Visibility = Visibility.Visible;
|
||||
ErrorTextBlock.Visibility = Visibility.Visible;
|
||||
ErrorTextBlock.Text = message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user