Added Login validation

This commit is contained in:
TheXamlGuy
2024-06-16 19:19:12 +01:00
parent f7b40efaea
commit 85cfcaf59d
3 changed files with 17 additions and 16 deletions
+8 -5
View File
@@ -23,14 +23,17 @@
PasswordChar="●"
Text="{Binding Password}">
<Interaction.Behaviors>
<KeyBindingTriggerBehaviour Gesture="Enter">
<KeyBindingTriggerBehaviour Gesture="Enter" IsEnabled="{Binding Password, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
<InvokeCommandAction Command="{Binding InvokeCommand}" />
</KeyBindingTriggerBehaviour>
</Interaction.Behaviors>
</TextBox>
<ProgressRing
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsActive="{Binding IsActive}" />
<Grid>
<TextBlock HorizontalAlignment="Center" Text="{ReflectionBinding Validation.Errors[Password]}" />
<ProgressRing
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsActive="{Binding IsActive}" />
</Grid>
</StackPanel>
</UserControl>
+1 -1
View File
@@ -61,7 +61,7 @@ public partial class CreateWalletViewModel :
{
if (args.PropertyName is string name)
{
Validation.Validate(name);
_ = Validation.Validate(name);
}
base.OnPropertyChanged(args);
+8 -10
View File
@@ -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<ActivateEventArgs<Wallet<string>>, bool>(Activate.As(new Wallet<string>(Password))), "The password is incorrect, please try again.")]))
{
if (await Mediator.Handle<ActivateEventArgs<Wallet<string>>, bool>(Activate.As(new Wallet<string>(Password))))
{
Publisher.Publish(Opened.As<Wallet>());
}
Publisher.Publish(Opened.As<Wallet>());
}
}
}