Username is now correctly persisted

Set credentials validation works as intended
Getting settings has default values
Add parent group in Move searchbox
Moving entries work as intended
Removed unreferenced code files
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-30 19:40:48 +02:00
parent e5353478f4
commit 8de493f987
18 changed files with 53 additions and 399 deletions

View File

@@ -51,9 +51,17 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
if (message.CreateSampleData)
{
_database.CreateGroup(_database.RootGroupId, "Banking");
_database.CreateGroup(_database.RootGroupId, "Email");
_database.CreateGroup(_database.RootGroupId, "Internet");
var bankingGroup = _database.CreateGroup(_database.RootGroupId, "Banking");
bankingGroup.Icon = Icon.Shop;
_database.UpdateGroup(bankingGroup);
var emailGroup = _database.CreateGroup(_database.RootGroupId, "Email");
emailGroup.Icon = Icon.Mail;
_database.UpdateGroup(emailGroup);
var internetGroup = _database.CreateGroup(_database.RootGroupId, "Internet");
internetGroup.Icon = Icon.World;
_database.UpdateGroup(internetGroup);
var sample1 = _database.CreateEntry(_database.RootGroupId);
_database.UpdateEntry(sample1.Id, EntryFieldName.Title, "Sample Entry" );

View File

@@ -26,7 +26,9 @@ namespace ModernKeePass.Application.Group.Queries.GetAllGroups
public IEnumerable<GroupVm> Handle(GetAllGroupsQuery message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
return _database.GetAllGroups(message.GroupId).Select(g => _mapper.Map<GroupVm>(g));
var groups = new List<GroupVm> {_mapper.Map<GroupVm>(_database.GetGroup(message.GroupId))};
groups.AddRange(_database.GetAllGroups(message.GroupId).Select(g => _mapper.Map<GroupVm>(g)));
return groups;
}
}
}

View File

@@ -13,7 +13,8 @@ namespace ModernKeePass.Infrastructure.UWP
{
try
{
return (T)Convert.ChangeType(_values[property], typeof(T));
var value = (T)Convert.ChangeType(_values[property], typeof(T));
return value == null ? defaultValue : value;
}
catch (InvalidCastException)
{

View File

@@ -51,7 +51,7 @@
<SolidColorBrush x:Key="HyperlinkPointerOverForegroundThemeBrush" Color="{ThemeResource MainColorLight}" />
<SolidColorBrush x:Key="SearchBoxForegroundThemeBrush" Color="{ThemeResource TextColorDark}" />
<SolidColorBrush x:Key="SearchBoxPointerOverBorderThemeBrush" Color="{ThemeResource MainColorLight}" />
<!--<SolidColorBrush x:Key="SearchBoxPointerOverBorderThemeBrush" Color="{ThemeResource MainColorLight}" />-->
<SolidColorBrush x:Key="SearchBoxPointerOverTextThemeBrush" Color="{ThemeResource MainColorLight}" />
<SolidColorBrush x:Key="SearchBoxFocusedBorderThemeBrush" Color="{ThemeResource MainColor}" />
<SolidColorBrush x:Key="SearchBoxButtonBackgroundThemeBrush" Color="{ThemeResource MainColor}" />

View File

@@ -107,7 +107,12 @@ namespace ModernKeePass.ViewModels
public string UserName
{
get { return SelectedItem.Username; }
set { SelectedItem.Username = value; }
set
{
SelectedItem.Username = value;
SetFieldValue(nameof(UserName), value).Wait();
RaisePropertyChanged(nameof(UserName));
}
}
public string Password
@@ -129,6 +134,7 @@ namespace ModernKeePass.ViewModels
{
SelectedItem.Url = value;
SetFieldValue(nameof(Url), value).Wait();
RaisePropertyChanged(nameof(Url));
}
}
@@ -253,7 +259,7 @@ namespace ModernKeePass.ViewModels
SaveCommand = new RelayCommand(async () => await SaveChanges(), () => Database.IsDirty);
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
MoveCommand = new RelayCommand<string>(async destination => await Move(destination), destination => _parent != null && string.IsNullOrEmpty(destination) && destination != _parent.Id);
MoveCommand = new RelayCommand<string>(async destination => await Move(destination), destination => _parent != null && !string.IsNullOrEmpty(destination) && destination != _parent.Id);
RestoreCommand = new RelayCommand(async () => await RestoreHistory());
DeleteCommand = new RelayCommand(async () => await AskForDelete());
GoBackCommand = new RelayCommand(() => _navigation.GoBack());

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.ViewModels;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
@@ -34,14 +33,9 @@ namespace ModernKeePass.Views
var file = await savePicker.PickSaveFileAsync().AsTask();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
var fileInfo = new FileInfo
{
Id = token,
Path = file.Path,
Name = file.DisplayName
};
Model.OpenFile(fileInfo);
Model.Token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.Name = file.Name;
Model.Path = file.Path;
}
}
}

View File

@@ -28,7 +28,9 @@ namespace ModernKeePass.Views
var file = e.Parameter as FileInfo;
if (file != null)
{
Model.OpenFile(file);
Model.Path = file.Path;
Model.Name = file.Name;
Model.Token = file.Id;
}
}
@@ -46,14 +48,9 @@ namespace ModernKeePass.Views
if (file == null) return;
// TODO: use service
var token = StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Path);
var fileInfo = new FileInfo
{
Path = file.Path,
Name = file.DisplayName,
Id = token
};
Model.OpenFile(fileInfo);
Model.Token = StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Path);
Model.Path = file.Path;
Model.Name = file.Name;
}
}
}

View File

@@ -117,19 +117,6 @@
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Initial">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxBorderThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ConfirmPasswordBox" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxBorderThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HyperlinkButton" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<interactivity:Interaction.Behaviors>
@@ -145,9 +132,6 @@
<core:DataTriggerBehavior Binding="{Binding IsKeyFileValid}" Value="True">
<core:GoToStateAction StateName="KeyFileValid"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding IsValid}" Value="True">
<core:GoToStateAction StateName="Initial"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Grid>
</UserControl>

View File

@@ -44,9 +44,8 @@ namespace ModernKeePass.Views.UserControls
var file = await picker.PickSingleFileAsync();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName;
Model.KeyFilePath = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFileText = file.Name;
}
private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e)
@@ -61,9 +60,8 @@ namespace ModernKeePass.Views.UserControls
var file = await savePicker.PickSaveFileAsync();
if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFilePath = token;
Model.KeyFileText = file.DisplayName;
Model.KeyFilePath = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
Model.KeyFileText = file.Name;
await Model.GenerateKeyFile();
}
}

View File

@@ -202,7 +202,7 @@ namespace ModernKeePass.Views.UserControls
{
args.Request.SearchSuggestionCollection.AppendResultSuggestion(
group.Title,
group.ParentGroupName,
group.ParentGroupName ?? string.Empty,
group.Id,
imageUri,
string.Empty);

View File

@@ -4,7 +4,7 @@ using Windows.UI.Xaml.Data;
namespace ModernKeePass.Converters
{
class EmptyStringToVisibilityConverter: IValueConverter
public class EmptyStringToVisibilityConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{

View File

@@ -16,7 +16,7 @@ namespace ModernKeePass.ViewModels.ListItems
public bool IsCreateSample
{
get { return _settings.GetSetting<bool>(Constants.Settings.Sample); }
get { return _settings.GetSetting(Constants.Settings.Sample, true); }
set { _settings.PutSetting(Constants.Settings.Sample, value); }
}
@@ -38,7 +38,7 @@ namespace ModernKeePass.ViewModels.ListItems
{
get
{
var version = _settings.GetSetting<string>(Constants.Settings.DefaultFileFormat);
var version = _settings.GetSetting(Constants.Settings.DefaultFileFormat, "4");
return FileFormats.FirstOrDefault(f => f.Version == version);
}
set { _settings.PutSetting(Constants.Settings.DefaultFileFormat, value.Version); }

View File

@@ -45,7 +45,7 @@ namespace ModernKeePass.ViewModels
Password = message.Password,
Name = "ModernKeePass",
Version = _settings.GetSetting(Constants.Settings.DefaultFileFormat, "4"),
CreateSampleData = _settings.GetSetting<bool>(Constants.Settings.Sample)
CreateSampleData = _settings.GetSetting<bool>(Constants.Settings.Sample, true)
});
var database = await _mediator.Send(new GetDatabaseQuery());

View File

@@ -1,5 +1,4 @@
using GalaSoft.MvvmLight;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
@@ -8,32 +7,28 @@ namespace ModernKeePass.ViewModels
private string _name;
private string _path;
private string _token;
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
public bool IsFileSelected => !string.IsNullOrEmpty(Token);
public string Token
{
get { return _token; }
set { Set(() => Token, ref _token, value); }
set
{
Set(() => Token, ref _token, value);
RaisePropertyChanged(nameof(IsFileSelected));
}
}
public string Name
{
get { return _name; }
private set { Set(() => Name, ref _name, value); }
set { Set(() => Name, ref _name, value); }
}
public string Path
{
get { return _path; }
private set { Set(() => Path, ref _path, value); }
}
public void OpenFile(FileInfo file)
{
Token = file.Id;
Name = file.Name;
Path = file.Path;
RaisePropertyChanged(nameof(IsFileSelected));
set { Set(() => Path, ref _path, value); }
}
}
}

View File

@@ -1,19 +0,0 @@
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using ModernKeePass.Common;
using ModernKeePass.Models;
namespace ModernKeePass.ViewModels
{
public class BreadcrumbVm
{
public RelayCommand<string> NavigateCommand { get; }
public BreadcrumbVm(INavigationService navigation)
{
NavigateCommand = new RelayCommand<string>(groupId =>
navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem {Id = groupId}),
groupId => !string.IsNullOrEmpty(groupId));
}
}
}

View File

@@ -1,175 +0,0 @@
using System;
using System.Text;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Commands.CreateDatabase;
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.OpenDatabase;
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
public class CompositeKeyVm : NotifyPropertyChangedBase
{
public enum StatusTypes
{
Normal = 0,
Error = 1,
Warning = 3,
Success = 5
}
public bool HasPassword
{
get { return _hasPassword; }
set
{
SetProperty(ref _hasPassword, value);
OnPropertyChanged(nameof(IsValid));
}
}
public bool HasKeyFile
{
get { return _hasKeyFile; }
set
{
SetProperty(ref _hasKeyFile, value);
OnPropertyChanged(nameof(IsValid));
}
}
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
public string Status
{
get { return _status; }
set { SetProperty(ref _status, value); }
}
public int StatusType
{
get { return (int)_statusType; }
set { SetProperty(ref _statusType, (StatusTypes)value); }
}
public string Password
{
get { return _password; }
set
{
_password = value;
OnPropertyChanged(nameof(PasswordComplexityIndicator));
StatusType = (int)StatusTypes.Normal;
Status = string.Empty;
}
}
public string KeyFilePath
{
get { return _keyFilePath; }
set
{
_keyFilePath = value;
OnPropertyChanged(nameof(IsValid));
}
}
public string KeyFileText
{
get { return _keyFileText; }
set { SetProperty(ref _keyFileText, value); }
}
public string RootGroupId { get; set; }
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery { Password = Password }).GetAwaiter().GetResult();
private bool _hasPassword;
private bool _hasKeyFile;
private bool _isOpening;
private string _password = string.Empty;
private string _status;
private StatusTypes _statusType;
private string _keyFilePath;
private string _keyFileText;
private readonly IMediator _mediator;
private readonly ISettingsProxy _settings;
private readonly IResourceProxy _resource;
public CompositeKeyVm() : this(
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<ISettingsProxy>(),
App.Services.GetRequiredService<IResourceProxy>())
{ }
public CompositeKeyVm(IMediator mediator, ISettingsProxy settings, IResourceProxy resource)
{
_mediator = mediator;
_settings = settings;
_resource = resource;
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
}
public async Task<bool> OpenDatabase(string databaseFilePath, bool createNew)
{
try
{
_isOpening = true;
OnPropertyChanged(nameof(IsValid));
if (createNew)
{
await _mediator.Send(new CreateDatabaseCommand
{
FilePath = databaseFilePath,
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
Name = "New Database",
CreateSampleData = _settings.GetSetting<bool>("Sample")
});
}
else
{
await _mediator.Send(new OpenDatabaseQuery
{
FilePath = databaseFilePath,
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
});
}
RootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
return true;
}
catch (ArgumentException)
{
var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n");
if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword"));
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
}
catch (Exception e)
{
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
UpdateStatus(error, StatusTypes.Error);
}
finally
{
_isOpening = false;
OnPropertyChanged(nameof(IsValid));
}
return false;
}
private void UpdateStatus(string text, StatusTypes type)
{
Status = text;
StatusType = (int)type;
}
}
}

View File

@@ -1,137 +0,0 @@
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;
public bool HasPassword
{
get { return _hasPassword; }
set
{
Set(() => HasPassword, ref _hasPassword, value);
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public bool HasKeyFile
{
get { return _hasKeyFile; }
set
{
Set(() => HasKeyFile, ref _hasKeyFile, value);
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string Status
{
get { return _status; }
set { Set(() => Status, ref _status, value); }
}
public string Password
{
get { return _password; }
set
{
_password = value;
RaisePropertyChanged(nameof(IsValid));
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string ConfirmPassword
{
get { return _confirmPassword; }
set
{
_confirmPassword = value;
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string KeyFilePath
{
get { return _keyFilePath; }
set
{
_keyFilePath = value;
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string KeyFileText
{
get { return _keyFileText; }
set { Set(() => KeyFileText, ref _keyFileText, value); }
}
public string OpenButtonLabel
{
get { return _openButtonLabel; }
set { Set(() => OpenButtonLabel, ref _openButtonLabel, value); }
}
public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password);
public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath);
public RelayCommand GenerateCredentialsCommand{ get; }
private bool _hasPassword;
private bool _hasKeyFile;
private string _password = string.Empty;
private string _confirmPassword;
private string _status;
private string _keyFilePath;
private string _keyFileText;
private string _openButtonLabel;
public SetCredentialsViewModel(): this(
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<ICredentialsProxy>(),
App.Services.GetRequiredService<IMessenger>(),
App.Services.GetRequiredService<IResourceProxy>()) { }
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()
{
_messenger.Send(new CredentialsSetMessage
{
Password = HasPassword ? Password : null,
KeyFilePath = HasKeyFile ? KeyFilePath : null
});
}
}
}

View File

@@ -83,7 +83,7 @@ namespace ModernKeePass.ViewModels
public bool IsPasswordValid => HasPassword && Password == ConfirmPassword || !HasPassword;
public bool IsKeyFileValid => HasKeyFile && !string.IsNullOrEmpty(KeyFilePath) || !HasKeyFile;
public bool IsValid => (IsPasswordValid || IsKeyFileValid) && (HasPassword || HasKeyFile);
public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath) && (HasPassword || HasKeyFile);
public RelayCommand GenerateCredentialsCommand{ get; }