mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 09:22:33 +00:00
Password input now works with document controller
This commit is contained in:
@@ -14,7 +14,10 @@
|
|||||||
#import "KdbPassword.h"
|
#import "KdbPassword.h"
|
||||||
#import "MPDatabaseVersion.h"
|
#import "MPDatabaseVersion.h"
|
||||||
|
|
||||||
@interface MPDocument ()
|
@interface MPDocument () {
|
||||||
|
@private
|
||||||
|
BOOL _isDecrypted;
|
||||||
|
}
|
||||||
|
|
||||||
@property (retain) KdbTree *tree;
|
@property (retain) KdbTree *tree;
|
||||||
@property (retain) NSURL *file;
|
@property (retain) NSURL *file;
|
||||||
@@ -34,6 +37,7 @@
|
|||||||
- (id)initWithVersion:(MPDatabaseVersion)version {
|
- (id)initWithVersion:(MPDatabaseVersion)version {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_isDecrypted = NO;
|
||||||
switch(version) {
|
switch(version) {
|
||||||
case MPDatabaseVersion3:
|
case MPDatabaseVersion3:
|
||||||
self.tree = [[[Kdb3Tree alloc] init] autorelease];
|
self.tree = [[[Kdb3Tree alloc] init] autorelease];
|
||||||
@@ -81,29 +85,10 @@
|
|||||||
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||||
self.file = url;
|
self.file = url;
|
||||||
return YES;
|
return YES;
|
||||||
// tell The window controller to display decrypt view
|
}
|
||||||
// - (void)openDocument:(id)sender {
|
|
||||||
//
|
|
||||||
// if(!self.passwordInputController) {
|
|
||||||
// self.passwordInputController = [[[MPPasswordInputController alloc] init] autorelease];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
|
||||||
// [openPanel setCanChooseDirectories:NO];
|
|
||||||
// [openPanel setCanChooseFiles:YES];
|
|
||||||
// [openPanel setCanCreateDirectories:NO];
|
|
||||||
// [openPanel setAllowsMultipleSelection:NO];
|
|
||||||
// [openPanel setAllowedFileTypes:@[ @"kdbx", @"kdb"]];
|
|
||||||
// [openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){
|
|
||||||
// if(result == NSFileHandlingPanelOKButton) {
|
|
||||||
// NSURL *file = [[openPanel URLs] lastObject];
|
|
||||||
// self.passwordInputController.fileURL = file;
|
|
||||||
// [self _setContentViewController:self.passwordInputController];
|
|
||||||
// }
|
|
||||||
// }];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
- (BOOL)isEntireFileLoaded {
|
||||||
|
return _isDecrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL {
|
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL {
|
||||||
@@ -123,6 +108,8 @@
|
|||||||
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
|
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
|
||||||
self.version = MPDatabaseVersion3;
|
self.version = MPDatabaseVersion3;
|
||||||
}
|
}
|
||||||
|
_isDecrypted = YES;
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (KdbPassword *)passwordHash {
|
- (KdbPassword *)passwordHash {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
|
|
||||||
- (void)showEntries;
|
- (void)showEntries;
|
||||||
- (void)showMainWindow:(id)sender;
|
- (void)showPasswordInput;
|
||||||
- (void)performFindPanelAction:(id)sender;
|
- (void)performFindPanelAction:(id)sender;
|
||||||
- (void)clearOutlineSelection:(id)sender;
|
- (void)clearOutlineSelection:(id)sender;
|
||||||
- (IBAction)editPassword:(id)sender;
|
- (IBAction)editPassword:(id)sender;
|
||||||
|
|||||||
@@ -221,9 +221,12 @@
|
|||||||
return [self.toolbarDelegate validateToolbarItem:theItem];
|
return [self.toolbarDelegate validateToolbarItem:theItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showMainWindow:(id)sender {
|
|
||||||
[[self window] makeKeyAndOrderFront:sender];
|
- (void)showPasswordInput {
|
||||||
//[self showWindow:self.window];
|
if(!self.passwordInputController) {
|
||||||
|
self.passwordInputController = [[[MPPasswordInputController alloc] init] autorelease];
|
||||||
|
}
|
||||||
|
[self _setContentViewController:self.passwordInputController];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clearOutlineSelection:(id)sender {
|
- (void)clearOutlineSelection:(id)sender {
|
||||||
@@ -268,12 +271,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Notifications
|
#pragma mark Notifications
|
||||||
|
|
||||||
- (void)didOpenDocument:(NSNotification *)notification {
|
|
||||||
[self _updateWindowTitle];
|
|
||||||
[self showEntries];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)showEntries {
|
- (void)showEntries {
|
||||||
if(!self.entryViewController) {
|
if(!self.entryViewController) {
|
||||||
_entryViewController = [[MPEntryViewController alloc] init];
|
_entryViewController = [[MPEntryViewController alloc] init];
|
||||||
@@ -281,6 +278,4 @@
|
|||||||
[self _setContentViewController:self.entryViewController];
|
[self _setContentViewController:self.entryViewController];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)changedFileType:(id)sender {
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
#import "MPPasswordEditViewController.h"
|
#import "MPPasswordEditViewController.h"
|
||||||
#import "MPKeyfilePathControlDelegate.h"
|
#import "MPKeyfilePathControlDelegate.h"
|
||||||
#import "MPDocumentWindowController.h"
|
#import "MPDocumentWindowController.h"
|
||||||
#import "MPDatabaseController.h"
|
#import "MPDocument.h"
|
||||||
#import "MPDatabaseDocument.h"
|
|
||||||
|
|
||||||
@interface MPPasswordEditViewController ()
|
@interface MPPasswordEditViewController ()
|
||||||
@property (assign) IBOutlet NSSecureTextField *passwordTextField;
|
@property (assign) IBOutlet NSSecureTextField *passwordTextField;
|
||||||
@@ -50,13 +49,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)_change:(id)sender {
|
- (IBAction)_change:(id)sender {
|
||||||
MPDatabaseDocument *database = [MPDatabaseController defaultController].database;
|
MPDocument *document = [[NSDocumentController sharedDocumentController] documentForWindow:[[self view] window]];
|
||||||
database.key = [self.keyfilePathControl URL];
|
if(document) {
|
||||||
database.password = [self.passwordTextField stringValue];
|
document.key = [self.keyfilePathControl URL];
|
||||||
[database save];
|
document.password = [self.passwordTextField stringValue];
|
||||||
|
}
|
||||||
MPDocumentWindowController *mainWindowController = (MPDocumentWindowController *)[[[self view] window] windowController];
|
MPDocumentWindowController *mainWindowController = (MPDocumentWindowController *)[[[self view] window] windowController];
|
||||||
[mainWindowController showEntries];
|
[mainWindowController showEntries];
|
||||||
// save automatically?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)_cancel:(id)sender {
|
- (IBAction)_cancel:(id)sender {
|
||||||
|
|||||||
@@ -10,6 +10,4 @@
|
|||||||
|
|
||||||
@interface MPPasswordInputController : MPViewController
|
@interface MPPasswordInputController : MPViewController
|
||||||
|
|
||||||
@property (retain) NSURL *fileURL;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "MPPasswordInputController.h"
|
#import "MPPasswordInputController.h"
|
||||||
#import "MPDatabaseController.h"
|
#import "MPDocument.h"
|
||||||
#import "MPKeyfilePathControlDelegate.h"
|
#import "MPKeyfilePathControlDelegate.h"
|
||||||
|
|
||||||
@interface MPPasswordInputController ()
|
@interface MPPasswordInputController ()
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
@property (assign) IBOutlet NSImageView *errorImageView;
|
@property (assign) IBOutlet NSImageView *errorImageView;
|
||||||
@property (assign) IBOutlet NSTextField *errorInfoTextField;
|
@property (assign) IBOutlet NSTextField *errorInfoTextField;
|
||||||
|
|
||||||
- (IBAction)_open:(id)sender;
|
- (IBAction)_decrypt:(id)sender;
|
||||||
- (void)_showError;
|
- (void)_showError;
|
||||||
- (void)_reset;
|
- (void)_reset;
|
||||||
|
|
||||||
@@ -31,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_fileURL release];
|
|
||||||
[_pathControlDelegate release];
|
[_pathControlDelegate release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
@@ -46,17 +45,16 @@
|
|||||||
return self.passwordTextField;
|
return self.passwordTextField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)_decrypt:(id)sender {
|
||||||
- (IBAction)_open:(id)sender {
|
MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument];
|
||||||
NSString *password = [self.passwordTextField stringValue];
|
if(document) {
|
||||||
NSURL *keyfile = [self.keyPathControl URL];
|
BOOL isOk = [document decryptWithPassword:[self.passwordTextField stringValue] keyFileURL:[self.keyPathControl URL]];
|
||||||
[self _reset];
|
if( isOk) {
|
||||||
MPDatabaseDocument *document = [[MPDatabaseController defaultController] openDatabase:self.fileURL
|
[self _showError];
|
||||||
password:password
|
}
|
||||||
keyfile:keyfile];
|
|
||||||
if(!document) {
|
|
||||||
[self _showError];
|
|
||||||
}
|
}
|
||||||
|
[self _reset];
|
||||||
|
// show entries
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_reset {
|
- (void)_reset {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>647</string>
|
<string>64C</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
<string key="NSClassName">NSApplication</string>
|
<string key="NSClassName">NSApplication</string>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSCustomView" id="1005">
|
<object class="NSCustomView" id="1005">
|
||||||
<reference key="NSNextResponder"/>
|
<nil key="NSNextResponder"/>
|
||||||
<int key="NSvFlags">268</int>
|
<int key="NSvFlags">268</int>
|
||||||
<array class="NSMutableArray" key="NSSubviews">
|
<array class="NSMutableArray" key="NSSubviews">
|
||||||
<object class="NSTextField" id="660673733">
|
<object class="NSTextField" id="660673733">
|
||||||
@@ -273,7 +273,6 @@
|
|||||||
</object>
|
</object>
|
||||||
</array>
|
</array>
|
||||||
<string key="NSFrameSize">{362, 268}</string>
|
<string key="NSFrameSize">{362, 268}</string>
|
||||||
<reference key="NSSuperview"/>
|
|
||||||
<reference key="NSNextKeyView" ref="204058255"/>
|
<reference key="NSNextKeyView" ref="204058255"/>
|
||||||
<string key="NSClassName">NSView</string>
|
<string key="NSClassName">NSView</string>
|
||||||
</object>
|
</object>
|
||||||
@@ -296,14 +295,6 @@
|
|||||||
</object>
|
</object>
|
||||||
<int key="connectionID">196</int>
|
<int key="connectionID">196</int>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBActionConnection" key="connection">
|
|
||||||
<string key="label">_open:</string>
|
|
||||||
<reference key="source" ref="1001"/>
|
|
||||||
<reference key="destination" ref="769513826"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">199</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBConnectionRecord">
|
<object class="IBConnectionRecord">
|
||||||
<object class="IBOutletConnection" key="connection">
|
<object class="IBOutletConnection" key="connection">
|
||||||
<string key="label">keyPathControl</string>
|
<string key="label">keyPathControl</string>
|
||||||
@@ -344,6 +335,14 @@
|
|||||||
</object>
|
</object>
|
||||||
<int key="connectionID">294</int>
|
<int key="connectionID">294</int>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBConnectionRecord">
|
||||||
|
<object class="IBActionConnection" key="connection">
|
||||||
|
<string key="label">_decrypt:</string>
|
||||||
|
<reference key="source" ref="1001"/>
|
||||||
|
<reference key="destination" ref="769513826"/>
|
||||||
|
</object>
|
||||||
|
<int key="connectionID">295</int>
|
||||||
|
</object>
|
||||||
</array>
|
</array>
|
||||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||||
<array key="orderedObjects">
|
<array key="orderedObjects">
|
||||||
@@ -519,6 +518,38 @@
|
|||||||
<float key="scoringTypeFloat">40</float>
|
<float key="scoringTypeFloat">40</float>
|
||||||
<int key="contentType">3</int>
|
<int key="contentType">3</int>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBNSLayoutConstraint" id="912203343">
|
||||||
|
<reference key="firstItem" ref="1005"/>
|
||||||
|
<int key="firstAttribute">9</int>
|
||||||
|
<int key="relation">0</int>
|
||||||
|
<reference key="secondItem" ref="204058255"/>
|
||||||
|
<int key="secondAttribute">9</int>
|
||||||
|
<float key="multiplier">1</float>
|
||||||
|
<object class="IBLayoutConstant" key="constant">
|
||||||
|
<double key="value">0.0</double>
|
||||||
|
</object>
|
||||||
|
<float key="priority">1000</float>
|
||||||
|
<reference key="containingView" ref="1005"/>
|
||||||
|
<int key="scoringType">9</int>
|
||||||
|
<float key="scoringTypeFloat">40</float>
|
||||||
|
<int key="contentType">2</int>
|
||||||
|
</object>
|
||||||
|
<object class="IBNSLayoutConstraint" id="273022298">
|
||||||
|
<reference key="firstItem" ref="204058255"/>
|
||||||
|
<int key="firstAttribute">3</int>
|
||||||
|
<int key="relation">1</int>
|
||||||
|
<reference key="secondItem" ref="1005"/>
|
||||||
|
<int key="secondAttribute">3</int>
|
||||||
|
<float key="multiplier">1</float>
|
||||||
|
<object class="IBNSLayoutSymbolicConstant" key="constant">
|
||||||
|
<double key="value">20</double>
|
||||||
|
</object>
|
||||||
|
<float key="priority">1000</float>
|
||||||
|
<reference key="containingView" ref="1005"/>
|
||||||
|
<int key="scoringType">9</int>
|
||||||
|
<float key="scoringTypeFloat">40</float>
|
||||||
|
<int key="contentType">3</int>
|
||||||
|
</object>
|
||||||
<object class="IBNSLayoutConstraint" id="335819100">
|
<object class="IBNSLayoutConstraint" id="335819100">
|
||||||
<reference key="firstItem" ref="333885704"/>
|
<reference key="firstItem" ref="333885704"/>
|
||||||
<int key="firstAttribute">11</int>
|
<int key="firstAttribute">11</int>
|
||||||
@@ -615,38 +646,6 @@
|
|||||||
<float key="scoringTypeFloat">24</float>
|
<float key="scoringTypeFloat">24</float>
|
||||||
<int key="contentType">2</int>
|
<int key="contentType">2</int>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBNSLayoutConstraint" id="912203343">
|
|
||||||
<reference key="firstItem" ref="1005"/>
|
|
||||||
<int key="firstAttribute">9</int>
|
|
||||||
<int key="relation">0</int>
|
|
||||||
<reference key="secondItem" ref="204058255"/>
|
|
||||||
<int key="secondAttribute">9</int>
|
|
||||||
<float key="multiplier">1</float>
|
|
||||||
<object class="IBLayoutConstant" key="constant">
|
|
||||||
<double key="value">0.0</double>
|
|
||||||
</object>
|
|
||||||
<float key="priority">1000</float>
|
|
||||||
<reference key="containingView" ref="1005"/>
|
|
||||||
<int key="scoringType">9</int>
|
|
||||||
<float key="scoringTypeFloat">40</float>
|
|
||||||
<int key="contentType">2</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBNSLayoutConstraint" id="273022298">
|
|
||||||
<reference key="firstItem" ref="204058255"/>
|
|
||||||
<int key="firstAttribute">3</int>
|
|
||||||
<int key="relation">1</int>
|
|
||||||
<reference key="secondItem" ref="1005"/>
|
|
||||||
<int key="secondAttribute">3</int>
|
|
||||||
<float key="multiplier">1</float>
|
|
||||||
<object class="IBNSLayoutSymbolicConstant" key="constant">
|
|
||||||
<double key="value">20</double>
|
|
||||||
</object>
|
|
||||||
<float key="priority">1000</float>
|
|
||||||
<reference key="containingView" ref="1005"/>
|
|
||||||
<int key="scoringType">9</int>
|
|
||||||
<float key="scoringTypeFloat">40</float>
|
|
||||||
<int key="contentType">3</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBNSLayoutConstraint" id="781301592">
|
<object class="IBNSLayoutConstraint" id="781301592">
|
||||||
<reference key="firstItem" ref="662046682"/>
|
<reference key="firstItem" ref="662046682"/>
|
||||||
<int key="firstAttribute">5</int>
|
<int key="firstAttribute">5</int>
|
||||||
@@ -1005,14 +1004,14 @@
|
|||||||
<reference ref="975314961"/>
|
<reference ref="975314961"/>
|
||||||
<reference ref="97094814"/>
|
<reference ref="97094814"/>
|
||||||
<reference ref="781301592"/>
|
<reference ref="781301592"/>
|
||||||
<reference ref="273022298"/>
|
|
||||||
<reference ref="912203343"/>
|
|
||||||
<reference ref="151404172"/>
|
<reference ref="151404172"/>
|
||||||
<reference ref="649511608"/>
|
<reference ref="649511608"/>
|
||||||
<reference ref="207368608"/>
|
<reference ref="207368608"/>
|
||||||
<reference ref="679367678"/>
|
<reference ref="679367678"/>
|
||||||
<reference ref="640603863"/>
|
<reference ref="640603863"/>
|
||||||
<reference ref="335819100"/>
|
<reference ref="335819100"/>
|
||||||
|
<reference ref="273022298"/>
|
||||||
|
<reference ref="912203343"/>
|
||||||
<reference ref="862589174"/>
|
<reference ref="862589174"/>
|
||||||
<reference ref="1040549598"/>
|
<reference ref="1040549598"/>
|
||||||
<reference ref="644024823"/>
|
<reference ref="644024823"/>
|
||||||
@@ -1084,7 +1083,7 @@
|
|||||||
<nil key="activeLocalization"/>
|
<nil key="activeLocalization"/>
|
||||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||||
<nil key="sourceID"/>
|
<nil key="sourceID"/>
|
||||||
<int key="maxID">294</int>
|
<int key="maxID">295</int>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBClassDescriber" key="IBDocument.Classes"/>
|
<object class="IBClassDescriber" key="IBDocument.Classes"/>
|
||||||
<int key="IBDocument.localizationMode">0</int>
|
<int key="IBDocument.localizationMode">0</int>
|
||||||
|
|||||||
Reference in New Issue
Block a user