Skip to content

Commit

Permalink
Merge pull request ResearchKit#128 from EricSiegNW/bug/FPHS-625
Browse files Browse the repository at this point in the history
FPHS 625
  • Loading branch information
Erin-Mounts committed Jun 3, 2016
2 parents cdca9d2 + 9938585 commit 4905faa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 8 additions & 4 deletions APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.h
Expand Up @@ -58,7 +58,6 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) {

@property (nonatomic, strong, nullable) NSString * firstName DEPRECATED_ATTRIBUTE;
@property (nonatomic, strong, nullable) NSString * lastName DEPRECATED_ATTRIBUTE;

@property (nonatomic, strong, nullable) NSString * email;
@property (nonatomic, strong, nullable) NSString * password;
@property (nonatomic, strong, nullable) NSString * sessionToken;
Expand Down Expand Up @@ -98,9 +97,6 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) {
@property (nonatomic, strong, nullable) NSDate *consentSignatureDate;
@property (nonatomic, strong, nullable) NSData *consentSignatureImage;

@property (nonatomic, strong, nullable) NSDate *downloadDataStartDate; // NOT stored in CoreData
@property (nonatomic, strong, nullable) NSDate *downloadDataEndDate; // NOT stored in CoreData

@property (nonatomic, getter=isSecondaryInfoSaved) BOOL secondaryInfoSaved;

/*********************************************************************************/
Expand All @@ -126,6 +122,14 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) {
@property (nonatomic, nullable) NSNumber * savedSharingScope;
@property (nonatomic, nullable) NSArray <NSString *> * dataGroups;

/*********************************************************************************/
#pragma mark - Stored In Memory Only
/*********************************************************************************/
@property (nonatomic, strong, nullable) NSString * cachedSessionToken; // Memory Only, can nil this out and sessionToken will remain safely in keychain
@property (nonatomic, strong, nullable) NSDate *downloadDataStartDate; // NOT stored in CoreData
@property (nonatomic, strong, nullable) NSDate *downloadDataEndDate; // NOT stored in CoreData


- (BOOL) isLoggedOut;

/**
Expand Down
14 changes: 14 additions & 0 deletions APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.m
Expand Up @@ -275,6 +275,20 @@ -(void)setPassword:(NSString *)password
[APCKeychainStore setString:[self hashIfNeeded:password] forKey:kPasswordPropertyName];
}

- (NSString *)sessionToken
{
if (self.cachedSessionToken == nil) {
self.cachedSessionToken = [APCKeychainStore stringForKey:kSessionTokenPropertyName];
}
return self.cachedSessionToken;
}

-(void)setSessionToken:(NSString *)sessionToken
{
self.cachedSessionToken = sessionToken;
[APCKeychainStore setString:[self hashIfNeeded:sessionToken] forKey:kSessionTokenPropertyName];
}

- (NSString *)externalId
{
return [APCKeychainStore stringForKey:kExternalIdPropertyName];
Expand Down
3 changes: 2 additions & 1 deletion APCAppCore/APCAppCore/Startup/APCAppDelegate.m
Expand Up @@ -273,7 +273,8 @@ - (void)applicationDidEnterBackground:(UIApplication *) __unused application
[[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithLong:uptime()] forKey:kLastUsedTimeKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
self.dataSubstrate.currentUser.sessionToken = nil;
// Clear the in memory token while preserving the keychain version
self.dataSubstrate.currentUser.cachedSessionToken = nil;

[self showSecureView];
}
Expand Down

0 comments on commit 4905faa

Please sign in to comment.