From 08ecc3c600ee909f52ebc289a3cb2aa4cfde8024 Mon Sep 17 00:00:00 2001 From: Eric Sieg Date: Fri, 24 Jun 2016 16:18:09 -0700 Subject: [PATCH] Only wipe local data if logging back in w/ a different username --- APCAppCore/APCAppCore/Startup/APCAppDelegate.h | 2 ++ APCAppCore/APCAppCore/Startup/APCAppDelegate.m | 16 ++++++++++------ .../Onboarding/SignIn/APCSignInViewController.m | 7 ++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/APCAppCore/APCAppCore/Startup/APCAppDelegate.h b/APCAppCore/APCAppCore/Startup/APCAppDelegate.h index ac532bc2..a72fdd7f 100644 --- a/APCAppCore/APCAppCore/Startup/APCAppDelegate.h +++ b/APCAppCore/APCAppCore/Startup/APCAppDelegate.h @@ -152,4 +152,6 @@ extern NSString *const kNewsFeedStoryBoardKey; */ - (void) resetAppAndProceedToSignIn; +- (void) clearPreviousUserData; + @end diff --git a/APCAppCore/APCAppCore/Startup/APCAppDelegate.m b/APCAppCore/APCAppCore/Startup/APCAppDelegate.m index 7fed2b05..cb678334 100644 --- a/APCAppCore/APCAppCore/Startup/APCAppDelegate.m +++ b/APCAppCore/APCAppCore/Startup/APCAppDelegate.m @@ -1246,12 +1246,7 @@ - (void) resetAppAndProceedToSignIn UIViewController * vc = [[UIViewController alloc] init]; vc.view.backgroundColor = [UIColor whiteColor]; appDelegate.window.rootViewController = vc; - - // Clear all user info, in case they log in or sign up as a different user afterwards - [appDelegate clearNSUserDefaults]; - [APCKeychainStore resetKeyChain]; - [appDelegate.dataSubstrate resetCoreData]; - + // This is all that is needed to force the re-registration of the PIN APCUser* user = [((id)appDelegate) onboardingManager].user; user.secondaryInfoSaved = NO; @@ -1259,4 +1254,13 @@ - (void) resetAppAndProceedToSignIn [self logOutAndGoToSignIn]; } +- (void) clearPreviousUserData +{ + // Clear all user info, in case they log in or sign up as a different user afterwards + APCAppDelegate * appDelegate = (APCAppDelegate*) [UIApplication sharedApplication].delegate; + [appDelegate clearNSUserDefaults]; + [APCKeychainStore resetKeyChain]; + [appDelegate.dataSubstrate resetCoreData]; +} + @end diff --git a/APCAppCore/APCAppCore/UI/Onboarding/SignIn/APCSignInViewController.m b/APCAppCore/APCAppCore/UI/Onboarding/SignIn/APCSignInViewController.m index b0cb1461..7c8c46f7 100644 --- a/APCAppCore/APCAppCore/UI/Onboarding/SignIn/APCSignInViewController.m +++ b/APCAppCore/APCAppCore/UI/Onboarding/SignIn/APCSignInViewController.m @@ -177,9 +177,14 @@ - (void) signIn APCUser * user = [self user]; - user.email = self.userHandleTextField.text; + if (user.email != nil && ![user.email isEqualToString:self.userHandleTextField.text] ) { + // Trying to log in as a different user, so clear cached data from the previously logged in user + [((APCAppDelegate*)[UIApplication sharedApplication].delegate) clearPreviousUserData]; + } + user.email = self.userHandleTextField.text; user.password = self.passwordTextField.text; + [user signInOnCompletion:^(NSError *error) { if (error) { [spinnerController dismissViewControllerAnimated:YES completion:^{