Log out active user and key when user is changed or deleted or unset.
This commit is contained in:
parent
975743adec
commit
fa0c80d6b3
@ -21,7 +21,7 @@
|
|||||||
@interface MPAppDelegate_Shared(Key)
|
@interface MPAppDelegate_Shared(Key)
|
||||||
|
|
||||||
- (BOOL)signInAsUser:(MPUserEntity *)user saveInContext:(NSManagedObjectContext *)moc usingMasterPassword:(NSString *)password;
|
- (BOOL)signInAsUser:(MPUserEntity *)user saveInContext:(NSManagedObjectContext *)moc usingMasterPassword:(NSString *)password;
|
||||||
- (void)signOutAnimated:(BOOL)animated;
|
- (void)signOut;
|
||||||
|
|
||||||
- (void)storeSavedKeyFor:(MPUserEntity *)user;
|
- (void)storeSavedKeyFor:(MPUserEntity *)user;
|
||||||
- (void)forgetSavedKeyFor:(MPUserEntity *)user;
|
- (void)forgetSavedKeyFor:(MPUserEntity *)user;
|
||||||
|
@ -115,17 +115,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)signOutAnimated:(BOOL)animated {
|
- (void)signOut {
|
||||||
|
|
||||||
if (self.key)
|
|
||||||
self.key = nil;
|
|
||||||
|
|
||||||
if ([[MPConfig get].sendInfo boolValue]) {
|
|
||||||
[Countly.sharedInstance userLoggedOut];
|
|
||||||
}
|
|
||||||
|
|
||||||
self.activeUser = nil;
|
self.activeUser = nil;
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPSignedOutNotification object:self userInfo:@{ @"animated": @(animated) }];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)signInAsUser:(MPUserEntity *)user saveInContext:(NSManagedObjectContext *)moc usingMasterPassword:(NSString *)password {
|
- (BOOL)signInAsUser:(MPUserEntity *)user saveInContext:(NSManagedObjectContext *)moc usingMasterPassword:(NSString *)password {
|
||||||
@ -191,7 +183,10 @@
|
|||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
inf( @"Logged in user: %@", user.userID );
|
inf( @"Logged in user: %@", user.userID );
|
||||||
|
user.lastUsed = [NSDate date];
|
||||||
|
self.activeUser = user;
|
||||||
|
|
||||||
if (![self.key isEqualToKey:tryKey]) {
|
if (![self.key isEqualToKey:tryKey]) {
|
||||||
// Upgrade the user's keyID if not at the default version yet.
|
// Upgrade the user's keyID if not at the default version yet.
|
||||||
@ -222,8 +217,6 @@
|
|||||||
err( @"While setting username: %@", exception );
|
err( @"While setting username: %@", exception );
|
||||||
}
|
}
|
||||||
|
|
||||||
user.lastUsed = [NSDate date];
|
|
||||||
self.activeUser = user;
|
|
||||||
[moc saveToStore];
|
[moc saveToStore];
|
||||||
|
|
||||||
// Perform a data sanity check now that we're logged in as the user to allow fixes that require the user's key.
|
// Perform a data sanity check now that we're logged in as the user to allow fixes that require the user's key.
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#import "MPAppDelegate_Key.h"
|
#import "MPAppDelegate_Key.h"
|
||||||
#import "NSManagedObjectModel+KCOrderedAccessorFix.h"
|
#import "NSManagedObjectModel+KCOrderedAccessorFix.h"
|
||||||
|
|
||||||
|
#import <Countly/Countly.h>
|
||||||
|
|
||||||
@interface MPAppDelegate_Shared()
|
@interface MPAppDelegate_Shared()
|
||||||
|
|
||||||
@property(strong, atomic) MPKey *key;
|
@property(strong, atomic) MPKey *key;
|
||||||
@ -63,14 +65,26 @@ static MPAppDelegate_Shared *instance;
|
|||||||
|
|
||||||
MPUserEntity *activeUser = [MPUserEntity existingObjectWithID:activeUserOID inContext:context];
|
MPUserEntity *activeUser = [MPUserEntity existingObjectWithID:activeUserOID inContext:context];
|
||||||
if (!activeUser)
|
if (!activeUser)
|
||||||
[self signOutAnimated:YES];
|
[self signOut];
|
||||||
|
|
||||||
return activeUser;
|
return activeUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setActiveUser:(MPUserEntity *)activeUser {
|
- (void)setActiveUser:(MPUserEntity *)activeUser {
|
||||||
|
|
||||||
self.activeUserOID = activeUser.permanentObjectID;
|
NSManagedObjectID *activeUserOID = activeUser.permanentObjectID;
|
||||||
|
if ([self.activeUserOID isEqualTo:activeUserOID])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (self.key)
|
||||||
|
self.key = nil;
|
||||||
|
|
||||||
|
if ([[MPConfig get].sendInfo boolValue])
|
||||||
|
[Countly.sharedInstance userLoggedOut];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPSignedOutNotification object:self];
|
||||||
|
|
||||||
|
self.activeUserOID = activeUserOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleCoordinatorError:(NSError *)error {
|
- (void)handleCoordinatorError:(NSError *)error {
|
||||||
|
@ -295,8 +295,6 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
|
|
||||||
- (void)selectUser:(NSMenuItem *)item {
|
- (void)selectUser:(NSMenuItem *)item {
|
||||||
|
|
||||||
[self signOutAnimated:NO];
|
|
||||||
|
|
||||||
NSManagedObjectContext *mainContext = [MPMacAppDelegate managedObjectContextForMainThreadIfReady];
|
NSManagedObjectContext *mainContext = [MPMacAppDelegate managedObjectContextForMainThreadIfReady];
|
||||||
self.activeUser = [MPUserEntity existingObjectWithID:[item representedObject] inContext:mainContext];
|
self.activeUser = [MPUserEntity existingObjectWithID:[item representedObject] inContext:mainContext];
|
||||||
}
|
}
|
||||||
@ -369,10 +367,12 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
|
|
||||||
return masterPassword;
|
return masterPassword;
|
||||||
} result:^(NSError *error) {
|
} result:^(NSError *error) {
|
||||||
|
PearlMainQueue( ^{
|
||||||
[self updateUsers];
|
[self updateUsers];
|
||||||
|
|
||||||
if (error && !(error.domain == NSCocoaErrorDomain && error.code == NSUserCancelledError))
|
if (error && !(error.domain == NSCocoaErrorDomain && error.code == NSUserCancelledError))
|
||||||
[[NSAlert alertWithError:error] runModal];
|
[[NSAlert alertWithError:error] runModal];
|
||||||
|
} );
|
||||||
}];
|
}];
|
||||||
}] resume];
|
}] resume];
|
||||||
}
|
}
|
||||||
@ -458,7 +458,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
|
|
||||||
- (IBAction)lock:(id)sender {
|
- (IBAction)lock:(id)sender {
|
||||||
|
|
||||||
[self signOutAnimated:YES];
|
[self signOut];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)terminate:(id)sender {
|
- (IBAction)terminate:(id)sender {
|
||||||
@ -642,6 +642,9 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
userItem.state = NSOffState;
|
userItem.state = NSOffState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mainActiveUser)
|
||||||
|
[self.sitesWindowController close];
|
||||||
|
|
||||||
[self updateMenuItems];
|
[self updateMenuItems];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@
|
|||||||
} );
|
} );
|
||||||
PearlAddNotificationObserver( NSWindowWillCloseNotification, self.window, [NSOperationQueue mainQueue],
|
PearlAddNotificationObserver( NSWindowWillCloseNotification, self.window, [NSOperationQueue mainQueue],
|
||||||
^(id host, NSNotification *note) {
|
^(id host, NSNotification *note) {
|
||||||
PearlRemoveNotificationObservers();
|
|
||||||
|
|
||||||
NSWindow *sheet = [self.window attachedSheet];
|
NSWindow *sheet = [self.window attachedSheet];
|
||||||
if (sheet)
|
if (sheet)
|
||||||
[self.window endSheet:sheet];
|
[self.window endSheet:sheet];
|
||||||
@ -86,6 +84,10 @@
|
|||||||
prof_finish( @"ui" );
|
prof_finish( @"ui" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
PearlRemoveNotificationObservers();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)replaceFonts:(NSView *)view {
|
- (void)replaceFonts:(NSView *)view {
|
||||||
|
|
||||||
if (view.window.backingScaleFactor == 1)
|
if (view.window.backingScaleFactor == 1)
|
||||||
@ -325,7 +327,7 @@
|
|||||||
[alert_ beginSheetModalForWindow:self.window completionHandler:nil];
|
[alert_ beginSheetModalForWindow:self.window completionHandler:nil];
|
||||||
|
|
||||||
if ([MPMacAppDelegate get].key)
|
if ([MPMacAppDelegate get].key)
|
||||||
[[MPMacAppDelegate get] signOutAnimated:YES];
|
[[MPMacAppDelegate get] signOut];
|
||||||
} );
|
} );
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -573,7 +575,6 @@
|
|||||||
}
|
}
|
||||||
prof_finish( @"newSites: %@", newSites );
|
prof_finish( @"newSites: %@", newSites );
|
||||||
|
|
||||||
dbg( @"newSites: %@", newSites );
|
|
||||||
if (![newSites isEqualToArray:self.sites])
|
if (![newSites isEqualToArray:self.sites])
|
||||||
PearlMainQueue( ^{
|
PearlMainQueue( ^{
|
||||||
self.sites = newSites;
|
self.sites = newSites;
|
||||||
|
@ -49,10 +49,7 @@
|
|||||||
|
|
||||||
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
||||||
^(MPAnswersViewController *self, NSNotification *note) {
|
^(MPAnswersViewController *self, NSNotification *note) {
|
||||||
if (![note.userInfo[@"animated"] boolValue])
|
|
||||||
[UIView setAnimationsEnabled:NO];
|
|
||||||
[[MPOverlaySegue dismissViewController:self] perform];
|
[[MPOverlaySegue dismissViewController:self] perform];
|
||||||
[UIView setAnimationsEnabled:YES];
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
} );
|
} );
|
||||||
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
||||||
^(MPCombinedViewController *self, NSNotification *note) {
|
^(MPCombinedViewController *self, NSNotification *note) {
|
||||||
[self setMode:MPCombinedModeUserSelection animated:[note.userInfo[@"animated"] boolValue]];
|
[self setMode:MPCombinedModeUserSelection];
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@
|
|||||||
|
|
||||||
- (void)setMode:(MPCombinedMode)mode {
|
- (void)setMode:(MPCombinedMode)mode {
|
||||||
|
|
||||||
[self setMode:mode animated:YES];
|
[self setMode:mode animated:[UIView areAnimationsEnabled]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMode:(MPCombinedMode)mode animated:(BOOL)animated {
|
- (void)setMode:(MPCombinedMode)mode animated:(BOOL)animated {
|
||||||
|
@ -64,10 +64,7 @@
|
|||||||
|
|
||||||
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
|
||||||
^(MPMessageViewController *self, NSNotification *note) {
|
^(MPMessageViewController *self, NSNotification *note) {
|
||||||
if (![note.userInfo[@"animated"] boolValue])
|
|
||||||
[UIView setAnimationsEnabled:NO];
|
|
||||||
[[MPOverlaySegue dismissViewController:self] perform];
|
[[MPOverlaySegue dismissViewController:self] perform];
|
||||||
[UIView setAnimationsEnabled:YES];
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
|
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
|
||||||
if (cell == self.signOutCell) {
|
if (cell == self.signOutCell) {
|
||||||
[self dismissPopup];
|
[self dismissPopup];
|
||||||
[[MPiOSAppDelegate get] signOutAnimated:YES];
|
[[MPiOSAppDelegate get] signOut];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell == self.feedbackCell)
|
if (cell == self.feedbackCell)
|
||||||
|
@ -363,7 +363,7 @@ typedef NS_OPTIONS( NSUInteger, MPPasswordsTips ) {
|
|||||||
[MPiOSAppDelegate managedObjectContextForMainThreadPerformBlock:^(NSManagedObjectContext *mainContext) {
|
[MPiOSAppDelegate managedObjectContextForMainThreadPerformBlock:^(NSManagedObjectContext *mainContext) {
|
||||||
// TODO: either move this into the app delegate or remove the duplicate signOutAnimated: call from the app delegate.
|
// TODO: either move this into the app delegate or remove the duplicate signOutAnimated: call from the app delegate.
|
||||||
if (![[MPiOSAppDelegate get] activeUserInContext:mainContext])
|
if (![[MPiOSAppDelegate get] activeUserInContext:mainContext])
|
||||||
[[MPiOSAppDelegate get] signOutAnimated:YES];
|
[[MPiOSAppDelegate get] signOut];
|
||||||
}];
|
}];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
@ -776,7 +776,7 @@ referenceSizeForFooterInSection:(NSInteger)section {
|
|||||||
self.masterPasswordChoice = nil;
|
self.masterPasswordChoice = nil;
|
||||||
|
|
||||||
if (activeUserState != MPActiveUserStateMinimized && (!self.active || [MPiOSAppDelegate get].activeUserOID)) {
|
if (activeUserState != MPActiveUserStateMinimized && (!self.active || [MPiOSAppDelegate get].activeUserOID)) {
|
||||||
[[MPiOSAppDelegate get] signOutAnimated:YES];
|
[[MPiOSAppDelegate get] signOut];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,16 +332,16 @@ void mpw_log_sink_pearl(const MPLogEvent *record) {
|
|||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
} result:^(NSError *error) {
|
} result:^(NSError *error) {
|
||||||
|
PearlMainQueue( ^{
|
||||||
[activityOverlay cancelOverlayAnimated:YES];
|
[activityOverlay cancelOverlayAnimated:YES];
|
||||||
|
|
||||||
if (error && !(error.domain == NSCocoaErrorDomain && error.code == NSUserCancelledError)) {
|
if (error && !(error.domain == NSCocoaErrorDomain && error.code == NSUserCancelledError)) {
|
||||||
PearlMainQueue( ^{
|
|
||||||
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error" message:[error localizedDescription]
|
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error" message:[error localizedDescription]
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[controller addAction:[UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleCancel handler:nil]];
|
[controller addAction:[UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleCancel handler:nil]];
|
||||||
[self.navigationController presentViewController:controller animated:YES completion:nil];
|
[self.navigationController presentViewController:controller animated:YES completion:nil];
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
} );
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +392,11 @@ void mpw_log_sink_pearl(const MPLogEvent *record) {
|
|||||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
|
||||||
inf( @"Did background" );
|
inf( @"Did background" );
|
||||||
if (![[MPiOSConfig get].rememberLogin boolValue])
|
if (![[MPiOSConfig get].rememberLogin boolValue]) {
|
||||||
[self signOutAnimated:NO];
|
[UIView setAnimationsEnabled:NO];
|
||||||
|
[self signOut];
|
||||||
|
[UIView setAnimationsEnabled:YES];
|
||||||
|
}
|
||||||
|
|
||||||
[self.hangDetector stop];
|
[self.hangDetector stop];
|
||||||
|
|
||||||
@ -661,7 +664,7 @@ void mpw_log_sink_pearl(const MPLogEvent *record) {
|
|||||||
[moc saveToStore];
|
[moc saveToStore];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[self signOutAnimated:YES];
|
[self signOut];
|
||||||
if (didReset)
|
if (didReset)
|
||||||
didReset();
|
didReset();
|
||||||
}]];
|
}]];
|
||||||
|
@ -31,7 +31,7 @@ mpw_expect() {
|
|||||||
[[ $file ]] && (( ! keep )) && rm "$file"
|
[[ $file ]] && (( ! keep )) && rm "$file"
|
||||||
|
|
||||||
printf '.'
|
printf '.'
|
||||||
local result=$(set -x; ./mpw -q "${args[@]}") err=$?
|
local result=$(./mpw -q "${args[@]}") err=$?
|
||||||
|
|
||||||
if (( err )); then
|
if (( err )); then
|
||||||
printf >&2 "Error (exit %d) mpw%s\n" "$err" "$(printf ' %q' "${args[@]}")"
|
printf >&2 "Error (exit %d) mpw%s\n" "$err" "$(printf ' %q' "${args[@]}")"
|
||||||
|
Loading…
Reference in New Issue
Block a user