mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-08 01:16:32 +03:00
merge important changes from feature/repository-window-locking
This commit is contained in:
@@ -52,7 +52,20 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
<DataTemplate DataType="{x:Type vm:LockedRepositoryViewModel}">
|
<DataTemplate DataType="{x:Type vm:LockedRepositoryViewModel}">
|
||||||
|
<StackPanel Margin="20"
|
||||||
|
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!" />
|
||||||
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</Window.DataTemplates>
|
</Window.DataTemplates>
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace KeyKeeper;
|
|||||||
|
|
||||||
public partial class RepositoryWindow: Window
|
public partial class RepositoryWindow: Window
|
||||||
{
|
{
|
||||||
public IPassStore? PassStore { private get; init; }
|
|
||||||
|
|
||||||
public RepositoryWindow()
|
public RepositoryWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -17,7 +15,5 @@ public partial class RepositoryWindow: Window
|
|||||||
protected override void OnOpened(EventArgs e)
|
protected override void OnOpened(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnOpened(e);
|
base.OnOpened(e);
|
||||||
if (PassStore!.Locked)
|
|
||||||
PassStore.Unlock(new CompositeKey("blablabla", null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using KeyKeeper.PasswordStore;
|
||||||
|
using KeyKeeper.PasswordStore.Crypto;
|
||||||
|
|
||||||
namespace KeyKeeper.ViewModels;
|
namespace KeyKeeper.ViewModels;
|
||||||
|
|
||||||
public class LockedRepositoryViewModel : ViewModelBase
|
public partial class LockedRepositoryViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
RepositoryWindowViewModel parent;
|
||||||
|
private IPassStore passStore;
|
||||||
|
private string password;
|
||||||
|
|
||||||
|
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,11 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using KeyKeeper.PasswordStore;
|
||||||
|
|
||||||
namespace KeyKeeper.ViewModels;
|
namespace KeyKeeper.ViewModels;
|
||||||
|
|
||||||
public class RepositoryWindowViewModel : ViewModelBase
|
public partial class RepositoryWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private object currentPage = new LockedRepositoryViewModel();
|
private object currentPage;
|
||||||
|
private IPassStore passStore;
|
||||||
|
|
||||||
public object CurrentPage
|
public object CurrentPage
|
||||||
{
|
{
|
||||||
get => currentPage;
|
get => currentPage;
|
||||||
set { currentPage = value; OnPropertyChanged(nameof(CurrentPage)); }
|
set { currentPage = value; OnPropertyChanged(nameof(CurrentPage)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositoryWindowViewModel(IPassStore store)
|
||||||
|
{
|
||||||
|
passStore = store;
|
||||||
|
UpdateLockStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLockStatus()
|
||||||
|
{
|
||||||
|
if ((currentPage == null || currentPage is LockedRepositoryViewModel) && !passStore.Locked)
|
||||||
|
SwitchToUnlocked();
|
||||||
|
else if ((currentPage == null || currentPage is UnlockedRepositoryViewModel) && passStore.Locked)
|
||||||
|
SwitchToLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToUnlocked()
|
||||||
|
{
|
||||||
|
CurrentPage = new UnlockedRepositoryViewModel(passStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToLocked()
|
||||||
|
{
|
||||||
|
CurrentPage = new LockedRepositoryViewModel(passStore, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
|
using KeyKeeper.PasswordStore;
|
||||||
|
|
||||||
namespace KeyKeeper.ViewModels;
|
namespace KeyKeeper.ViewModels;
|
||||||
|
|
||||||
public class UnlockedRepositoryViewModel : ViewModelBase
|
public class UnlockedRepositoryViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
private IPassStore passStore;
|
||||||
|
|
||||||
|
public UnlockedRepositoryViewModel(IPassStore store)
|
||||||
|
{
|
||||||
|
passStore = store;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -84,8 +84,7 @@ namespace KeyKeeper.Views
|
|||||||
{
|
{
|
||||||
var repositoryWindow = new RepositoryWindow()
|
var repositoryWindow = new RepositoryWindow()
|
||||||
{
|
{
|
||||||
DataContext = new RepositoryWindowViewModel(),
|
DataContext = new RepositoryWindowViewModel(store),
|
||||||
PassStore = store,
|
|
||||||
WindowStartupLocation = WindowStartupLocation.CenterScreen
|
WindowStartupLocation = WindowStartupLocation.CenterScreen
|
||||||
};
|
};
|
||||||
repositoryWindow.Closed += (s, e) => this.Show();
|
repositoryWindow.Closed += (s, e) => this.Show();
|
||||||
|
|||||||
Reference in New Issue
Block a user