mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-17 18:19:26 +00:00
Re-enabled password request before saving a database that has no password and key
Stripped logging code Fixed issue with save panel not being updated correctly when panel is just reshown
This commit is contained in:
@@ -53,6 +53,7 @@ APPKIT_EXTERN NSString *const MPDocumnetDidChangeCurrentEntryNotification;
|
|||||||
|
|
||||||
|
|
||||||
+ (KPKVersion)versionForFileType:(NSString *)fileType;
|
+ (KPKVersion)versionForFileType:(NSString *)fileType;
|
||||||
|
+ (NSString *)fileTypeForVersion:(KPKVersion)version;
|
||||||
|
|
||||||
#pragma mark Lock/Decrypt
|
#pragma mark Lock/Decrypt
|
||||||
- (void)lockDatabase:(id)sender;
|
- (void)lockDatabase:(id)sender;
|
||||||
|
|||||||
@@ -72,6 +72,19 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
|
|||||||
return KPKUnknownVersion;
|
return KPKUnknownVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSString *)fileTypeForVersion:(KPKVersion)version {
|
||||||
|
switch(version) {
|
||||||
|
case KPKLegacyVersion:
|
||||||
|
return MPLegacyDocumentUTI;
|
||||||
|
|
||||||
|
case KPKXmlVersion:
|
||||||
|
return MPXMLDocumentUTI;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return @"Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+ (BOOL)autosavesInPlace {
|
+ (BOOL)autosavesInPlace {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@@ -103,8 +116,12 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||||
|
if(!self.hasPasswordOrKey) {
|
||||||
|
return NO; // No password or key. No save possible
|
||||||
|
}
|
||||||
KPKPassword *password = [[KPKPassword alloc] initWithPassword:self.password key:self.key];
|
KPKPassword *password = [[KPKPassword alloc] initWithPassword:self.password key:self.key];
|
||||||
KPKVersion version = [[self class] versionForFileType:(NSString *)typeName];
|
NSString *fileType = [self fileTypeFromLastRunSavePanel];
|
||||||
|
KPKVersion version = [[self class] versionForFileType:fileType];
|
||||||
if(version == KPKUnknownVersion) {
|
if(version == KPKUnknownVersion) {
|
||||||
if(outError != NULL) {
|
if(outError != NULL) {
|
||||||
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:nil];
|
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:nil];
|
||||||
@@ -174,10 +191,20 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
|
|||||||
}
|
}
|
||||||
self.savePanelViewController.savePanel = savePanel;
|
self.savePanelViewController.savePanel = savePanel;
|
||||||
self.savePanelViewController.document = self;
|
self.savePanelViewController.document = self;
|
||||||
|
|
||||||
[savePanel setAccessoryView:[self.savePanelViewController view]];
|
[savePanel setAccessoryView:[self.savePanelViewController view]];
|
||||||
|
[self.savePanelViewController updateView];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)fileTypeFromLastRunSavePanel {
|
||||||
|
if(self.savePanelViewController) {
|
||||||
|
return [[self class] fileTypeForVersion:self.savePanelViewController.selectedVersion];
|
||||||
|
}
|
||||||
|
return [self fileType];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)writeXMLToURL:(NSURL *)url {
|
- (void)writeXMLToURL:(NSURL *)url {
|
||||||
NSData *xmlData = [self.tree xmlData];
|
NSData *xmlData = [self.tree xmlData];
|
||||||
[xmlData writeToURL:url atomically:YES];
|
[xmlData writeToURL:url atomically:YES];
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import "MPPasswordEditWindowController.h"
|
||||||
|
|
||||||
@class MPViewController;
|
@class MPViewController;
|
||||||
@class MPEntryViewController;
|
@class MPEntryViewController;
|
||||||
@@ -14,7 +15,7 @@
|
|||||||
@class MPPasswordInputController;
|
@class MPPasswordInputController;
|
||||||
@class MPOutlineViewController;
|
@class MPOutlineViewController;
|
||||||
|
|
||||||
@interface MPDocumentWindowController : NSWindowController
|
@interface MPDocumentWindowController : NSWindowController <MPPasswordEditWindowDelegate>
|
||||||
|
|
||||||
@property (readonly, strong) MPPasswordInputController *passwordInputController;
|
@property (readonly, strong) MPPasswordInputController *passwordInputController;
|
||||||
@property (readonly, strong) MPEntryViewController *entryViewController;
|
@property (readonly, strong) MPEntryViewController *entryViewController;
|
||||||
@@ -46,4 +47,7 @@
|
|||||||
- (void)createGroup:(id)sender;
|
- (void)createGroup:(id)sender;
|
||||||
- (void)toggleInspector:(id)sender;
|
- (void)toggleInspector:(id)sender;
|
||||||
|
|
||||||
|
#pragma mark MPPasswordEditWindowDelegater
|
||||||
|
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
@interface MPDocumentWindowController () {
|
@interface MPDocumentWindowController () {
|
||||||
@private
|
@private
|
||||||
id _firstResponder;
|
id _firstResponder;
|
||||||
|
BOOL _saveAfterPasswordChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (strong) IBOutlet NSSplitView *splitView;
|
@property (strong) IBOutlet NSSplitView *splitView;
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
self = [super initWithWindowNibName:@"DocumentWindow" owner:self];
|
self = [super initWithWindowNibName:@"DocumentWindow" owner:self];
|
||||||
if( self ) {
|
if( self ) {
|
||||||
_firstResponder = nil;
|
_firstResponder = nil;
|
||||||
|
_saveAfterPasswordChange = NO;
|
||||||
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
||||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||||
_entryViewController = [[MPEntryViewController alloc] init];
|
_entryViewController = [[MPEntryViewController alloc] init];
|
||||||
@@ -153,6 +155,7 @@
|
|||||||
|
|
||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
- (void)saveDocument:(id)sender {
|
- (void)saveDocument:(id)sender {
|
||||||
|
_saveAfterPasswordChange = NO;
|
||||||
MPDocument *document = [self document];
|
MPDocument *document = [self document];
|
||||||
NSString *fileType = [document fileType];
|
NSString *fileType = [document fileType];
|
||||||
/* we did open as legacy */
|
/* we did open as legacy */
|
||||||
@@ -166,16 +169,21 @@
|
|||||||
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
|
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
|
||||||
|
|
||||||
[[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]];
|
[[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]];
|
||||||
|
|
||||||
[alert beginSheetModalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
[alert beginSheetModalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!document.hasPasswordOrKey) {
|
else if(!document.hasPasswordOrKey) {
|
||||||
NSLog(@"No Password and/or kefile set");// warning if no password ist set!
|
_saveAfterPasswordChange = YES;
|
||||||
|
[self editPassword:sender];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* All set and good ready to save */
|
||||||
[[self document] saveDocument:sender];
|
[[self document] saveDocument:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
- (void)exportDatabase:(id)sender {
|
- (void)exportDatabase:(id)sender {
|
||||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||||
[savePanel setAllowsOtherFileTypes:YES];
|
[savePanel setAllowsOtherFileTypes:YES];
|
||||||
@@ -274,7 +282,10 @@
|
|||||||
- (void)editPassword:(id)sender {
|
- (void)editPassword:(id)sender {
|
||||||
if(!self.passwordEditWindowController) {
|
if(!self.passwordEditWindowController) {
|
||||||
self.passwordEditWindowController = [[MPPasswordEditWindowController alloc] initWithDocument:[self document]];
|
self.passwordEditWindowController = [[MPPasswordEditWindowController alloc] initWithDocument:[self document]];
|
||||||
|
self.passwordEditWindowController.delegate = self;
|
||||||
}
|
}
|
||||||
|
/* Disallow empty password if we want to save afterwards, otherwise the dialog keeps poping up */
|
||||||
|
self.passwordEditWindowController.allowsEmptyPasswordOrKey = !_saveAfterPasswordChange;
|
||||||
[NSApp beginSheet:[self.passwordEditWindowController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
[NSApp beginSheet:[self.passwordEditWindowController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,6 +403,14 @@
|
|||||||
[_outlineViewController showOutline];
|
[_outlineViewController showOutline];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark MPPasswordEditWindowDelegate
|
||||||
|
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey {
|
||||||
|
if(changedPasswordOrKey && _saveAfterPasswordChange) {
|
||||||
|
[self saveDocument:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Helper
|
#pragma mark Helper
|
||||||
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab {
|
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab {
|
||||||
if(!self.documentSettingsWindowController) {
|
if(!self.documentSettingsWindowController) {
|
||||||
|
|||||||
@@ -260,7 +260,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
id item = userInfo[@"NSObject"];
|
id item = userInfo[@"NSObject"];
|
||||||
id representedObject = [item representedObject];
|
id representedObject = [item representedObject];
|
||||||
if([representedObject isKindOfClass:[KPKGroup class]]) {
|
if([representedObject isKindOfClass:[KPKGroup class]]) {
|
||||||
NSLog(@"expanded:%@",representedObject);
|
|
||||||
KPKGroup *group = (KPKGroup *)representedObject;
|
KPKGroup *group = (KPKGroup *)representedObject;
|
||||||
group.isExpanded = YES;
|
group.isExpanded = YES;
|
||||||
}
|
}
|
||||||
@@ -270,7 +269,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
id item = userInfo[@"NSObject"];
|
id item = userInfo[@"NSObject"];
|
||||||
id representedObject = [item representedObject];
|
id representedObject = [item representedObject];
|
||||||
if([representedObject isKindOfClass:[KPKGroup class]]) {
|
if([representedObject isKindOfClass:[KPKGroup class]]) {
|
||||||
NSLog(@"collapsed:%@",representedObject);
|
|
||||||
KPKGroup *group = (KPKGroup *)representedObject;
|
KPKGroup *group = (KPKGroup *)representedObject;
|
||||||
group.isExpanded = NO;
|
group.isExpanded = NO;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,17 @@
|
|||||||
@class MPDocument;
|
@class MPDocument;
|
||||||
@class HNHRoundedSecureTextField;
|
@class HNHRoundedSecureTextField;
|
||||||
|
|
||||||
|
@protocol MPPasswordEditWindowDelegate <NSObject>
|
||||||
|
|
||||||
|
@optional
|
||||||
|
/**
|
||||||
|
* Get's called on dismissing the password editor.
|
||||||
|
* @param changedPasswordOrKey YES if the password and/or key was saved (not necessairly changed!);
|
||||||
|
*/
|
||||||
|
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface MPPasswordEditWindowController : MPSheetWindowController <NSTextFieldDelegate>
|
@interface MPPasswordEditWindowController : MPSheetWindowController <NSTextFieldDelegate>
|
||||||
|
|
||||||
@property (weak) IBOutlet HNHRoundedSecureTextField *passwordTextField;
|
@property (weak) IBOutlet HNHRoundedSecureTextField *passwordTextField;
|
||||||
@@ -19,6 +30,9 @@
|
|||||||
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
||||||
@property (weak) IBOutlet NSTextField *errorTextField;
|
@property (weak) IBOutlet NSTextField *errorTextField;
|
||||||
@property (weak) IBOutlet NSButton *changePasswordButton;
|
@property (weak) IBOutlet NSButton *changePasswordButton;
|
||||||
|
@property (nonatomic,assign) BOOL allowsEmptyPasswordOrKey;
|
||||||
|
|
||||||
|
@property (weak) id<MPPasswordEditWindowDelegate> delegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dedicated initializer for the Windowcontroller
|
* Dedicated initializer for the Windowcontroller
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
- (id)initWithDocument:(MPDocument *)document {
|
- (id)initWithDocument:(MPDocument *)document {
|
||||||
self = [super initWithWindowNibName:@"PasswordEditWindow"];
|
self = [super initWithWindowNibName:@"PasswordEditWindow"];
|
||||||
if(self){
|
if(self){
|
||||||
|
_allowsEmptyPasswordOrKey = YES;
|
||||||
_showPassword = NO;
|
_showPassword = NO;
|
||||||
_hasValidPasswordOrKey = NO;
|
_hasValidPasswordOrKey = NO;
|
||||||
_document = document;
|
_document = document;
|
||||||
@@ -84,10 +85,16 @@
|
|||||||
_document.password = [self.passwordTextField stringValue];
|
_document.password = [self.passwordTextField stringValue];
|
||||||
_document.key = [self.keyfilePathControl URL];
|
_document.key = [self.keyfilePathControl URL];
|
||||||
[self dismissSheet:NSRunStoppedResponse];
|
[self dismissSheet:NSRunStoppedResponse];
|
||||||
|
if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishPasswordEditing:)]) {
|
||||||
|
[self.delegate didFinishPasswordEditing:YES];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)cancel:(id)sender {
|
- (IBAction)cancel:(id)sender {
|
||||||
[self dismissSheet:NSRunAbortedResponse];
|
[self dismissSheet:NSRunAbortedResponse];
|
||||||
|
if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishPasswordEditing:)]) {
|
||||||
|
[self.delegate didFinishPasswordEditing:NO];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)clearKey:(id)sender {
|
- (IBAction)clearKey:(id)sender {
|
||||||
@@ -138,7 +145,7 @@
|
|||||||
BOOL hasPasswordOrKey = (hasKey || hasPassword);
|
BOOL hasPasswordOrKey = (hasKey || hasPassword);
|
||||||
keyOk = hasKey ? keyOk : YES;
|
keyOk = hasKey ? keyOk : YES;
|
||||||
passwordOk = hasPassword ? passwordOk : YES;
|
passwordOk = hasPassword ? passwordOk : YES;
|
||||||
self.hasValidPasswordOrKey = passwordOk && keyOk;
|
self.hasValidPasswordOrKey = (hasPasswordOrKey || self.allowsEmptyPasswordOrKey ) && passwordOk && keyOk;
|
||||||
|
|
||||||
if(!hasPasswordOrKey) {
|
if(!hasPasswordOrKey) {
|
||||||
[self.errorTextField setTextColor:[NSColor controlTextColor]];
|
[self.errorTextField setTextColor:[NSColor controlTextColor]];
|
||||||
|
|||||||
@@ -19,5 +19,9 @@
|
|||||||
|
|
||||||
@property (nonatomic, weak) IBOutlet NSPopUpButton *fileTypePopupButton;
|
@property (nonatomic, weak) IBOutlet NSPopUpButton *fileTypePopupButton;
|
||||||
@property (nonatomic, weak) IBOutlet NSTextField *infoTextField;
|
@property (nonatomic, weak) IBOutlet NSTextField *infoTextField;
|
||||||
|
/**
|
||||||
|
* Updates the view to current state
|
||||||
|
*/
|
||||||
|
- (void)updateView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
}
|
}
|
||||||
[self.fileTypePopupButton setMenu:menu];
|
[self.fileTypePopupButton setMenu:menu];
|
||||||
[self.infoTextField setHidden:YES];
|
[self.infoTextField setHidden:YES];
|
||||||
[self _updateView];
|
[self updateView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)setFileType:(id)sender {
|
- (IBAction)setFileType:(id)sender {
|
||||||
@@ -59,11 +59,11 @@
|
|||||||
- (void)setDocument:(MPDocument *)document {
|
- (void)setDocument:(MPDocument *)document {
|
||||||
if(_document != document) {
|
if(_document != document) {
|
||||||
_document = document;
|
_document = document;
|
||||||
[self _updateView];
|
[self updateView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_updateView {
|
- (void)updateView {
|
||||||
switch(self.document.versionForFileType) {
|
switch(self.document.versionForFileType) {
|
||||||
case KPKLegacyVersion:
|
case KPKLegacyVersion:
|
||||||
[self.fileTypePopupButton selectItemAtIndex:1];
|
[self.fileTypePopupButton selectItemAtIndex:1];
|
||||||
|
|||||||
Reference in New Issue
Block a user