mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-12 19:36:32 +03:00
merge branch PasswordDialogWindow
This commit is contained in:
@@ -4,6 +4,7 @@ using Avalonia.Input;
|
|||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using KeyKeeper.PasswordStore;
|
using KeyKeeper.PasswordStore;
|
||||||
|
using KeyKeeper.PasswordStore.Crypto;
|
||||||
using KeyKeeper.ViewModels;
|
using KeyKeeper.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -39,19 +40,28 @@ namespace KeyKeeper.Views
|
|||||||
{
|
{
|
||||||
if (file.TryGetLocalPath() is string path)
|
if (file.TryGetLocalPath() is string path)
|
||||||
{
|
{
|
||||||
(DataContext as MainWindowViewModel)!.CreateVault(path);
|
var passwordDialog = new PasswordDialog();
|
||||||
OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
|
await passwordDialog.ShowDialog(this);
|
||||||
|
if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
|
||||||
{
|
{
|
||||||
Key = new PasswordStore.Crypto.CompositeKey("blablabla", null),
|
var compositeKey = new CompositeKey(passwordDialog.Password, null);
|
||||||
LockTimeoutSeconds = 800,
|
var passStoreAccessor = new PassStoreFileAccessor(
|
||||||
}));
|
filename: path,
|
||||||
|
create: true,
|
||||||
|
createOptions: new StoreCreationOptions()
|
||||||
|
{
|
||||||
|
Key = compositeKey,
|
||||||
|
LockTimeoutSeconds = 800
|
||||||
|
});
|
||||||
|
IPassStore passStore = passStoreAccessor;
|
||||||
|
OpenRepositoryWindow(passStore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
|
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Открываем диалог выбора файла
|
|
||||||
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||||
{
|
{
|
||||||
Title = "Открыть хранилище паролей",
|
Title = "Открыть хранилище паролей",
|
||||||
@@ -74,21 +84,21 @@ namespace KeyKeeper.Views
|
|||||||
var file = files[0];
|
var file = files[0];
|
||||||
if (file.TryGetLocalPath() is string path)
|
if (file.TryGetLocalPath() is string path)
|
||||||
{
|
{
|
||||||
(DataContext as MainWindowViewModel)!.OpenVault(path);
|
|
||||||
OpenRepositoryWindow(new PassStoreFileAccessor(path, false, null));
|
OpenRepositoryWindow(new PassStoreFileAccessor(path, false, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenRepositoryWindow(IPassStore store)
|
private void OpenRepositoryWindow(IPassStore passStore)
|
||||||
{
|
{
|
||||||
var repositoryWindow = new RepositoryWindow(new RepositoryWindowViewModel(store))
|
var repositoryWindow = new RepositoryWindow(new RepositoryWindowViewModel(passStore))
|
||||||
{
|
{
|
||||||
WindowStartupLocation = WindowStartupLocation.CenterScreen
|
WindowStartupLocation = WindowStartupLocation.CenterScreen
|
||||||
};
|
};
|
||||||
|
|
||||||
repositoryWindow.Closed += (s, e) => this.Show();
|
repositoryWindow.Closed += (s, e) => this.Show();
|
||||||
repositoryWindow.Show();
|
repositoryWindow.Show();
|
||||||
this.Hide();
|
this.Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/KeyKeeper/Views/PasswordDialog.axaml
Normal file
54
src/KeyKeeper/Views/PasswordDialog.axaml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="KeyKeeper.Views.PasswordDialog"
|
||||||
|
Title="Создание хранилища"
|
||||||
|
Width="350"
|
||||||
|
Height="230">
|
||||||
|
|
||||||
|
<StackPanel Margin="20" VerticalAlignment="Center">
|
||||||
|
|
||||||
|
<TextBlock Text="Set Master Password"
|
||||||
|
FontSize="16"
|
||||||
|
FontWeight="Bold"
|
||||||
|
Margin="0,0,0,15"/>
|
||||||
|
|
||||||
|
<!-- Поле для пароля (звездочки) -->
|
||||||
|
<StackPanel Margin="0,0,0,10">
|
||||||
|
<TextBlock Text="Password:" Margin="0,0,0,5"/>
|
||||||
|
<TextBox x:Name="PasswordBox"
|
||||||
|
PasswordChar="*"
|
||||||
|
Width="250"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Поле для подтверждения (звездочки) -->
|
||||||
|
<StackPanel Margin="0,0,0,15">
|
||||||
|
<TextBlock Text="Confirm Password:" Margin="0,0,0,5"/>
|
||||||
|
<TextBox x:Name="ConfirmPasswordBox"
|
||||||
|
PasswordChar="*"
|
||||||
|
Width="250"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Сообщение об ошибке -->
|
||||||
|
<TextBlock x:Name="ErrorText"
|
||||||
|
Text="Passwords do not match"
|
||||||
|
Foreground="Red"
|
||||||
|
FontSize="12"
|
||||||
|
Margin="0,0,0,10"
|
||||||
|
IsVisible="False"/>
|
||||||
|
|
||||||
|
<!-- Кнопки -->
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
|
||||||
|
<Button Content="Cancel"
|
||||||
|
Width="80"
|
||||||
|
Height="30"
|
||||||
|
Click="CancelButton_Click"/>
|
||||||
|
|
||||||
|
<Button Content="Create"
|
||||||
|
Width="80"
|
||||||
|
Height="30"
|
||||||
|
Click="CreateButton_Click"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</Window>
|
||||||
65
src/KeyKeeper/Views/PasswordDialog.axaml.cs
Normal file
65
src/KeyKeeper/Views/PasswordDialog.axaml.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace KeyKeeper.Views
|
||||||
|
{
|
||||||
|
public partial class PasswordDialog : Window
|
||||||
|
{
|
||||||
|
public string Password { get; private set; } = "";
|
||||||
|
public bool Created { get; private set; } = false;
|
||||||
|
|
||||||
|
public PasswordDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var passwordBox = this.FindControl<TextBox>("PasswordBox");
|
||||||
|
var confirmBox = this.FindControl<TextBox>("ConfirmPasswordBox");
|
||||||
|
var errorText = this.FindControl<TextBlock>("ErrorText");
|
||||||
|
|
||||||
|
string password = passwordBox?.Text ?? "";
|
||||||
|
string confirmPassword = confirmBox?.Text ?? "";
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmPassword))
|
||||||
|
{
|
||||||
|
ShowError("Password cannot be empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password != confirmPassword)
|
||||||
|
{
|
||||||
|
ShowError("Passwords don't match");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Password = password;
|
||||||
|
Created = true;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowError(string message)
|
||||||
|
{
|
||||||
|
var errorText = this.FindControl<TextBlock>("ErrorText");
|
||||||
|
if (errorText != null)
|
||||||
|
{
|
||||||
|
errorText.Text = message;
|
||||||
|
errorText.IsVisible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Created = false;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user