From 85cfcaf59dcf79651ac0de673a2978bafa5a5c73 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Sun, 16 Jun 2024 19:19:12 +0100 Subject: [PATCH] Added Login validation --- Wallet.Avalonia/OpenWalletView.axaml | 13 ++++++++----- Wallet/CreateWalletViewModel.cs | 2 +- Wallet/OpenWalletViewModel.cs | 18 ++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Wallet.Avalonia/OpenWalletView.axaml b/Wallet.Avalonia/OpenWalletView.axaml index ba6b593..e246c30 100644 --- a/Wallet.Avalonia/OpenWalletView.axaml +++ b/Wallet.Avalonia/OpenWalletView.axaml @@ -23,14 +23,17 @@ PasswordChar="●" Text="{Binding Password}"> - + - + + + + diff --git a/Wallet/CreateWalletViewModel.cs b/Wallet/CreateWalletViewModel.cs index 4a8babe..ff843ad 100644 --- a/Wallet/CreateWalletViewModel.cs +++ b/Wallet/CreateWalletViewModel.cs @@ -61,7 +61,7 @@ public partial class CreateWalletViewModel : { if (args.PropertyName is string name) { - Validation.Validate(name); + _ = Validation.Validate(name); } base.OnPropertyChanged(args); diff --git a/Wallet/OpenWalletViewModel.cs b/Wallet/OpenWalletViewModel.cs index 1a3b04a..abe05a7 100644 --- a/Wallet/OpenWalletViewModel.cs +++ b/Wallet/OpenWalletViewModel.cs @@ -1,21 +1,21 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using System.Diagnostics.CodeAnalysis; using Toolkit.Foundation; namespace Wallet; public partial class OpenWalletViewModel : Observable { - private readonly IValidation validation; + [ObservableProperty] + private IValidation validation; [ObservableProperty] private string? name; + [MaybeNull] [ObservableProperty] - private string? password; - - [ObservableProperty] - private string? repeatedPassword; + private string password; public OpenWalletViewModel(IValidation validation, IServiceProvider provider, @@ -35,12 +35,10 @@ public partial class OpenWalletViewModel : Observable { using (await new ActivityLock(this)) { - if (Password is { Length: > 0 }) + if (await validation.Validate(() => Password, [new ValidationRule(async () => + await Mediator.Handle>, bool>(Activate.As(new Wallet(Password))), "The password is incorrect, please try again.")])) { - if (await Mediator.Handle>, bool>(Activate.As(new Wallet(Password)))) - { - Publisher.Publish(Opened.As()); - } + Publisher.Publish(Opened.As()); } } }