mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Update master key works
Key file creation works Code cleanup
This commit is contained in:
43
WinAppCommon/ViewModels/Items/SettingsSecurityVm.cs
Normal file
43
WinAppCommon/ViewModels/Items/SettingsSecurityVm.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||
|
||||
namespace ModernKeePass.ViewModels.ListItems
|
||||
{
|
||||
public class SettingsSecurityVm
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ISettingsProxy _settings;
|
||||
private readonly INavigationService _navigation;
|
||||
|
||||
public SettingsSecurityVm(): this(
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<ISettingsProxy>(),
|
||||
App.Services.GetRequiredService<IMessenger>(),
|
||||
App.Services.GetRequiredService<INavigationService>()) { }
|
||||
|
||||
public SettingsSecurityVm(IMediator mediator, ISettingsProxy settings, IMessenger messenger, INavigationService navigation)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_settings = settings;
|
||||
_navigation = navigation;
|
||||
|
||||
messenger.Register<CredentialsSetMessage>(this, async message => await UpdateDatabaseCredentials(message));
|
||||
}
|
||||
|
||||
public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
|
||||
{
|
||||
await _mediator.Send(new UpdateCredentialsCommand
|
||||
{
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
//TODO: Add Toast
|
||||
}
|
||||
}
|
||||
}
|
@@ -49,7 +49,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
|
||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
|
||||
|
||||
public string Status
|
||||
{
|
||||
@@ -113,7 +113,6 @@ namespace ModernKeePass.ViewModels
|
||||
private string _keyFileText;
|
||||
private string _openButtonLabel;
|
||||
|
||||
|
||||
public OpenDatabaseControlVm() : this(
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<IResourceProxy>(),
|
||||
|
@@ -1,14 +1,18 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SetCredentialsViewModel : ObservableObject
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ICredentialsProxy _credentials;
|
||||
private readonly IMessenger _messenger;
|
||||
|
||||
@@ -87,7 +91,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password);
|
||||
|
||||
public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && KeyFilePath != string.Empty;
|
||||
public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath);
|
||||
|
||||
public RelayCommand GenerateCredentialsCommand{ get; }
|
||||
|
||||
@@ -100,13 +104,25 @@ namespace ModernKeePass.ViewModels
|
||||
private string _keyFileText;
|
||||
private string _openButtonLabel;
|
||||
|
||||
public SetCredentialsViewModel(): this(App.Services.GetRequiredService<ICredentialsProxy>(), App.Services.GetRequiredService<IMessenger>()) { }
|
||||
public SetCredentialsViewModel(): this(
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<ICredentialsProxy>(),
|
||||
App.Services.GetRequiredService<IMessenger>(),
|
||||
App.Services.GetRequiredService<IResourceProxy>()) { }
|
||||
|
||||
public SetCredentialsViewModel(ICredentialsProxy credentials, IMessenger messenger)
|
||||
public SetCredentialsViewModel(IMediator mediator, ICredentialsProxy credentials, IMessenger messenger, IResourceProxy resource)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_credentials = credentials;
|
||||
_messenger = messenger;
|
||||
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
|
||||
|
||||
_keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
}
|
||||
|
||||
public async Task GenerateKeyFile()
|
||||
{
|
||||
await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = KeyFilePath});
|
||||
}
|
||||
|
||||
private void GenerateCredentials()
|
||||
|
@@ -52,6 +52,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsDatabaseVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsNewVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsSaveVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsSecurityVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\NewVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\OpenVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\RecentVm.cs" />
|
||||
|
Reference in New Issue
Block a user