diff options
author | Zsika Phillip <protocol86@users.noreply.github.com> | 2017-09-21 16:35:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 16:35:27 -0700 |
commit | f333bd5c188d553057c2dcc099b5da42edd1d495 (patch) | |
tree | 7f2925d9353c2fc6d267843500aac0077e7b176d /Firebase | |
parent | 93bcf42a0bf3254f57f948fcdf6411b9f4184f1e (diff) |
User meta data (#292)
* Add user metadata
* Small improvements
* Addresses comments
* Fixes broken tests
Adds FIRUserMetadata to unbrella file.
Diffstat (limited to 'Firebase')
-rw-r--r-- | Firebase/Auth/Source/FIRUser.m | 5 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRUserMetadata.m | 64 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRUserMetadata_Internal.h | 38 | ||||
-rw-r--r-- | Firebase/Auth/Source/Public/FIRUser.h | 6 | ||||
-rw-r--r-- | Firebase/Auth/Source/Public/FIRUserMetadata.h | 47 | ||||
-rw-r--r-- | Firebase/Auth/Source/Public/FirebaseAuth.h | 15 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.h | 10 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.m | 10 |
8 files changed, 187 insertions, 8 deletions
diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index 8fdb178..d24a2bf 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -40,6 +40,7 @@ #import "FIRGetOOBConfirmationCodeResponse.h" #import "FIRSetAccountInfoRequest.h" #import "FIRSetAccountInfoResponse.h" +#import "FIRUserMetadata_Internal.h" #import "FIRVerifyAssertionRequest.h" #import "FIRVerifyAssertionResponse.h" #import "FIRVerifyCustomTokenRequest.h" @@ -397,7 +398,9 @@ static void callInMainThreadWithAuthDataResultAndError( _photoURL = user.photoURL; _phoneNumber = user.phoneNumber; _hasEmailPasswordCredential = user.passwordHash.length > 0; - + _metadata = + [[FIRUserMetadata alloc]initWithCreationDate:user.creationDate + lastSignInDate:user.lastLoginDate]; NSMutableDictionary<NSString *, FIRUserInfoImpl *> *providerData = [NSMutableDictionary dictionary]; for (FIRGetAccountInfoResponseProviderUserInfo *providerUserInfo in user.providerUserInfo) { diff --git a/Firebase/Auth/Source/FIRUserMetadata.m b/Firebase/Auth/Source/FIRUserMetadata.m new file mode 100644 index 0000000..65ca15c --- /dev/null +++ b/Firebase/Auth/Source/FIRUserMetadata.m @@ -0,0 +1,64 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "FIRUserMetadata_Internal.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation FIRUserMetadata + +/** @var kCreationDateCodingKey + @brief The key used to encode the creationDate property for NSSecureCoding. + */ +static NSString *const kCreationDateCodingKey = @"creationDate"; + +/** @var kLastSignInDateCodingKey + @brief The key used to encode the lastSignInDate property for NSSecureCoding. + */ +static NSString *const kLastSignInDateCodingKey = @"lastSignInDate"; + +- (nullable instancetype)initWithCreationDate:(NSDate *)creationDate + lastSignInDate:(NSDate *)lastSignInDate { + self = [super init]; + if (self) { + _creationDate = [creationDate copy]; + _lastSignInDate = [lastSignInDate copy]; + } + return self; +} + +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { + NSDate *creationDate = + [aDecoder decodeObjectOfClass:[NSDate class] forKey:kCreationDateCodingKey]; + NSDate *lastSignInDate = + [aDecoder decodeObjectOfClass:[NSDate class] forKey:kLastSignInDateCodingKey]; + return [self initWithCreationDate:creationDate lastSignInDate:lastSignInDate]; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder { + [aCoder encodeObject:_creationDate forKey:kCreationDateCodingKey]; + [aCoder encodeObject:_lastSignInDate forKey:kLastSignInDateCodingKey]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Auth/Source/FIRUserMetadata_Internal.h b/Firebase/Auth/Source/FIRUserMetadata_Internal.h new file mode 100644 index 0000000..3fd1efc --- /dev/null +++ b/Firebase/Auth/Source/FIRUserMetadata_Internal.h @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import <Foundation/Foundation.h> + +#import "FIRUserMetadata.h" + +NS_ASSUME_NONNULL_BEGIN + +/** @extension FIRUserMetadata + @brief An internal class used to expose internal methods of FIRUserMetadata. + */ +@interface FIRUserMetadata () <NSSecureCoding> + +/** @fn initWithCreationDate + @brief Designated initializer. + @param creationDate The creation date of the corresponding user. + @param lastSignInDate The date of the last recorded sign-in of the corresponding user. + */ +- (nullable instancetype)initWithCreationDate:(NSDate *)creationDate + lastSignInDate:(NSDate *)lastSignInDate NS_DESIGNATED_INITIALIZER; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Auth/Source/Public/FIRUser.h b/Firebase/Auth/Source/Public/FIRUser.h index d87f639..f0a5619 100644 --- a/Firebase/Auth/Source/Public/FIRUser.h +++ b/Firebase/Auth/Source/Public/FIRUser.h @@ -23,6 +23,7 @@ @class FIRPhoneAuthCredential; @class FIRUserProfileChangeRequest; +@class FIRUserMetadata; NS_ASSUME_NONNULL_BEGIN @@ -84,6 +85,11 @@ FIR_SWIFT_NAME(User) */ @property(nonatomic, readonly, nonnull) NSArray<id<FIRUserInfo>> *providerData; +/** @property metadata + @brief Metadata associated with the Firebase user in question. + */ +@property(nonatomic, readonly, nonnull) FIRUserMetadata *metadata; + /** @fn init @brief This class should not be instantiated. @remarks To retrieve the current user, use @c FIRAuth.currentUser. To sign a user diff --git a/Firebase/Auth/Source/Public/FIRUserMetadata.h b/Firebase/Auth/Source/Public/FIRUserMetadata.h new file mode 100644 index 0000000..1b72ee1 --- /dev/null +++ b/Firebase/Auth/Source/Public/FIRUserMetadata.h @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import <Foundation/Foundation.h> + +#import "FIRAuthSwiftNameSupport.h" + +NS_ASSUME_NONNULL_BEGIN + +/** @class FIRUserMetdata + @brief A data class representing the metadata corresponding to a Firebase user. + */ +FIR_SWIFT_NAME(UserMetadata) +@interface FIRUserMetadata : NSObject + +/** @property lastSignInDate + @brief Stores the last sign in date for the corresponding Firebase user. + */ +@property (copy, nonatomic, readonly, nullable) NSDate *lastSignInDate; + +/** @property creationDate + @brief Stores the creation date for the corresponding Firebase user. + */ +@property (copy, nonatomic, readonly, nullable) NSDate *creationDate; + +/** @fn init + @brief This class should not be initialized manually, an instance of this class can be obtained + from a Firebase user object. + */ +- (instancetype)init NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firebase/Auth/Source/Public/FirebaseAuth.h b/Firebase/Auth/Source/Public/FirebaseAuth.h index cd17b45..0cc5905 100644 --- a/Firebase/Auth/Source/Public/FirebaseAuth.h +++ b/Firebase/Auth/Source/Public/FirebaseAuth.h @@ -16,12 +16,6 @@ #import <Foundation/Foundation.h> -#import "FIREmailAuthProvider.h" -#import "FIRFacebookAuthProvider.h" -#import "FIRGitHubAuthProvider.h" -#import "FIRGoogleAuthProvider.h" -#import "FIROAuthProvider.h" -#import "FIRTwitterAuthProvider.h" #import "FIRActionCodeSettings.h" #import "FIRAdditionalUserInfo.h" #import "FIRAuth.h" @@ -29,9 +23,16 @@ #import "FIRAuthDataResult.h" #import "FIRAuthErrors.h" #import "FIRAuthSwiftNameSupport.h" +#import "FirebaseAuthVersion.h" +#import "FIREmailAuthProvider.h" +#import "FIRFacebookAuthProvider.h" +#import "FIRGitHubAuthProvider.h" +#import "FIRGoogleAuthProvider.h" +#import "FIROAuthProvider.h" +#import "FIRTwitterAuthProvider.h" #import "FIRUser.h" #import "FIRUserInfo.h" -#import "FirebaseAuthVersion.h" +#import "FIRUserMetadata.h" #if TARGET_OS_IOS #import "FIRAuthUIDelegate.h" diff --git a/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.h b/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.h index 009f3c1..6c30dbe 100644 --- a/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.h +++ b/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.h @@ -100,6 +100,16 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, strong, readonly, nullable) NSURL *photoURL; +/** @property creationDate + @brief The user's creation date. + */ +@property(nonatomic, strong, readonly, nullable) NSDate *creationDate; + +/** @property lastSignInDate + @brief The user's last login date. + */ +@property(nonatomic, strong, readonly, nullable) NSDate *lastLoginDate; + /** @property providerUserInfo @brief The user's profiles at the associated identity providers. */ diff --git a/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.m b/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.m index 6a16593..19ab64a 100644 --- a/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.m +++ b/Firebase/Auth/Source/RPCs/FIRGetAccountInfoResponse.m @@ -65,6 +65,16 @@ static NSString *const kErrorKey = @"error"; if (photoURL) { _photoURL = [NSURL URLWithString:photoURL]; } + if ([dictionary[@"createdAt"] isKindOfClass:[NSString class]]) { + // Divide by 1000 in order to convert miliseconds to seconds. + NSTimeInterval creationDateTimeInterval = [dictionary[@"createdAt"] doubleValue] / 1000; + _creationDate = [NSDate dateWithTimeIntervalSince1970:creationDateTimeInterval]; + } + if ([dictionary[@"lastLoginAt"] isKindOfClass:[NSString class]]) { + // Divide by 1000 in order to convert miliseconds to seconds + NSTimeInterval creationDateTimeInterval = [dictionary[@"lastLoginAt"] doubleValue] / 1000; + _lastLoginDate = [NSDate dateWithTimeIntervalSince1970:creationDateTimeInterval]; + } _emailVerified = [dictionary[@"emailVerified"] boolValue]; _passwordHash = [dictionary[@"passwordHash"] copy]; _phoneNumber = [dictionary[@"phoneNumber"] copy]; |