New user on Mac.
[ADDED] Mac: Support for creating a new user.
This commit is contained in:
parent
5e1e88bdeb
commit
96d97d95e1
@ -154,6 +154,35 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
||||
}
|
||||
|
||||
- (IBAction)newUser:(NSMenuItem *)sender {
|
||||
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:@"New User"
|
||||
defaultButton:@"Create User" alternateButton:nil otherButton:@"Cancel"
|
||||
informativeTextWithFormat:@"To begin, enter your full name.\n\n"
|
||||
@"IMPORTANT: Enter your name correctly, including the right capitalization, "
|
||||
@"as you would on an official document."];
|
||||
NSTextField *nameField = [[NSTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
|
||||
[alert setAccessoryView:nameField];
|
||||
[alert layout];
|
||||
[nameField becomeFirstResponder];
|
||||
if ([alert runModal] != NSAlertDefaultReturn)
|
||||
return;
|
||||
|
||||
NSString *name = [(NSSecureTextField *)alert.accessoryView stringValue];
|
||||
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
|
||||
MPUserEntity *newUser = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass( [MPUserEntity class] )
|
||||
inManagedObjectContext:moc];
|
||||
newUser.name = name;
|
||||
[moc saveToStore];
|
||||
NSError *error = nil;
|
||||
if (![moc obtainPermanentIDsForObjects:@[ newUser ] error:&error])
|
||||
err(@"Failed to obtain permanent object ID for new user: %@", error);
|
||||
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
[self updateUsers];
|
||||
[self setActiveUser:newUser];
|
||||
[self showPasswordWindow];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)lock:(id)sender {
|
||||
|
@ -58,6 +58,7 @@
|
||||
}];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserverForName:MPSignedOutNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
|
||||
_activeElementOID = nil;
|
||||
[self.window close];
|
||||
}];
|
||||
|
||||
@ -143,27 +144,28 @@
|
||||
self.contentContainer.alphaValue = 0;
|
||||
[self.progressView startAnimation:nil];
|
||||
self.inProgress = YES;
|
||||
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
|
||||
|
||||
NSString *password = [(NSSecureTextField *)alert.accessoryView stringValue];
|
||||
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc_) {
|
||||
NSError *error = nil;
|
||||
MPUserEntity *activeUser_ = (MPUserEntity *)[moc existingObjectWithID:activeUser.objectID error:&error];
|
||||
MPUserEntity *activeUser_ = (MPUserEntity *)[moc_ existingObjectWithID:activeUser.objectID error:&error];
|
||||
if (!activeUser_)
|
||||
err(@"Failed to retrieve active use while logging in: %@", error);
|
||||
|
||||
BOOL success = [[MPMacAppDelegate get] signInAsUser:activeUser saveInContext:moc
|
||||
usingMasterPassword:[(NSSecureTextField *)alert.accessoryView stringValue]];
|
||||
err(@"Failed to retrieve active use while logging in: %@", error);
|
||||
|
||||
BOOL success = [[MPMacAppDelegate get] signInAsUser:activeUser saveInContext:moc_
|
||||
usingMasterPassword:password];
|
||||
self.inProgress = NO;
|
||||
|
||||
|
||||
dispatch_async( dispatch_get_main_queue(), ^{
|
||||
[self.progressView stopAnimation:nil];
|
||||
|
||||
|
||||
if (success)
|
||||
self.contentContainer.alphaValue = 1;
|
||||
else {
|
||||
[[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{
|
||||
NSLocalizedDescriptionKey : PearlString( @"Incorrect master password for user %@",
|
||||
activeUser.name )
|
||||
}]] beginSheetModalForWindow:self.window modalDelegate:self
|
||||
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:MPAlertIncorrectMP];
|
||||
NSLocalizedDescriptionKey : PearlString( @"Incorrect master password for user %@", activeUser.name )
|
||||
}]] beginSheetModalForWindow:self.window modalDelegate:self
|
||||
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:MPAlertIncorrectMP];
|
||||
}
|
||||
} );
|
||||
}];
|
||||
@ -194,7 +196,7 @@
|
||||
NSError *error = nil;
|
||||
NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error];
|
||||
if (!siteResults)
|
||||
err(@"While fetching elements for completion: %@", error);
|
||||
err(@"While fetching elements for completion: %@", error);
|
||||
else if ([siteResults count]) {
|
||||
_activeElementOID = ((NSManagedObject *)[siteResults objectAtIndex:0]).objectID;
|
||||
for (MPElementEntity *element in siteResults)
|
||||
|
Loading…
Reference in New Issue
Block a user