mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-17 18:16:28 +03:00
make unlocking work, no exception handling yet
This commit is contained in:
@@ -56,10 +56,12 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<TextBox x:Name="UnlockPasswordEdit"
|
||||
Text="{Binding UnlockPassword, Mode=TwoWay}"
|
||||
PasswordChar="*"
|
||||
Width="450" />
|
||||
|
||||
<Button x:Name="UnlockButton"
|
||||
Command="{Binding TryUnlock}"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="Black"
|
||||
Content="Unlock!" />
|
||||
|
||||
@@ -1,13 +1,44 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using KeyKeeper.PasswordStore;
|
||||
using KeyKeeper.PasswordStore.Crypto;
|
||||
|
||||
namespace KeyKeeper.ViewModels;
|
||||
|
||||
public class LockedRepositoryViewModel : ViewModelBase
|
||||
public partial class LockedRepositoryViewModel : ViewModelBase
|
||||
{
|
||||
RepositoryWindowViewModel parent;
|
||||
private IPassStore passStore;
|
||||
private string password;
|
||||
|
||||
public LockedRepositoryViewModel(IPassStore store)
|
||||
public LockedRepositoryViewModel(IPassStore store, RepositoryWindowViewModel parent)
|
||||
{
|
||||
passStore = store;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public string UnlockPassword
|
||||
{
|
||||
get => password;
|
||||
set { password = value; OnPropertyChanged(nameof(UnlockPassword)); }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void TryUnlock()
|
||||
{
|
||||
try
|
||||
{
|
||||
passStore.Unlock(new CompositeKey(UnlockPassword, null));
|
||||
parent.UpdateLockStatus();
|
||||
} catch (PassStoreFileException e)
|
||||
{
|
||||
// TODO
|
||||
Console.WriteLine("pass store file exception: " + e.Message);
|
||||
} catch (Exception e)
|
||||
{
|
||||
// TODO
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using KeyKeeper.PasswordStore;
|
||||
|
||||
namespace KeyKeeper.ViewModels;
|
||||
|
||||
public class RepositoryWindowViewModel : ViewModelBase
|
||||
public partial class RepositoryWindowViewModel : ViewModelBase
|
||||
{
|
||||
private object currentPage;
|
||||
private IPassStore passStore;
|
||||
@@ -19,7 +22,7 @@ public class RepositoryWindowViewModel : ViewModelBase
|
||||
UpdateLockStatus();
|
||||
}
|
||||
|
||||
private void UpdateLockStatus()
|
||||
public void UpdateLockStatus()
|
||||
{
|
||||
if ((currentPage == null || currentPage is LockedRepositoryViewModel) && !passStore.Locked)
|
||||
SwitchToUnlocked();
|
||||
@@ -29,11 +32,11 @@ public class RepositoryWindowViewModel : ViewModelBase
|
||||
|
||||
private void SwitchToUnlocked()
|
||||
{
|
||||
currentPage = new UnlockedRepositoryViewModel(passStore);
|
||||
CurrentPage = new UnlockedRepositoryViewModel(passStore);
|
||||
}
|
||||
|
||||
private void SwitchToLocked()
|
||||
{
|
||||
currentPage = new LockedRepositoryViewModel(passStore);
|
||||
CurrentPage = new LockedRepositoryViewModel(passStore, this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user