You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.7 KiB

6 years ago
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRUserInfoImpl.h"
  17. #import "FIRGetAccountInfoResponse.h"
  18. /** @var kProviderIDCodingKey
  19. @brief The key used to encode the providerID property for NSSecureCoding.
  20. */
  21. static NSString *const kProviderIDCodingKey = @"providerID";
  22. /** @var kUserIDCodingKey
  23. @brief The key used to encode the userID property for NSSecureCoding.
  24. */
  25. static NSString *const kUserIDCodingKey = @"userID";
  26. /** @var kDisplayNameCodingKey
  27. @brief The key used to encode the displayName property for NSSecureCoding.
  28. */
  29. static NSString *const kDisplayNameCodingKey = @"displayName";
  30. /** @var kProfileURLCodingKey
  31. @brief The key used to encode the profileURL property for NSSecureCoding.
  32. */
  33. static NSString *const kProfileURLCodingKey = @"profileURL";
  34. /** @var kPhotoURLCodingKey
  35. @brief The key used to encode the photoURL property for NSSecureCoding.
  36. */
  37. static NSString *const kPhotoURLCodingKey = @"photoURL";
  38. /** @var kEmailCodingKey
  39. @brief The key used to encode the email property for NSSecureCoding.
  40. */
  41. static NSString *const kEmailCodingKey = @"email";
  42. /** @var kPhoneNumberCodingKey
  43. @brief The key used to encode the phoneNumber property for NSSecureCoding.
  44. */
  45. static NSString *const kPhoneNumberCodingKey = @"phoneNumber";
  46. @implementation FIRUserInfoImpl
  47. @synthesize providerID = _providerID;
  48. @synthesize uid = _userID;
  49. @synthesize displayName = _displayName;
  50. @synthesize photoURL = _photoURL;
  51. @synthesize email = _email;
  52. @synthesize phoneNumber = _phoneNumber;
  53. + (nullable instancetype)userInfoWithGetAccountInfoResponseProviderUserInfo:
  54. (FIRGetAccountInfoResponseProviderUserInfo *)providerUserInfo {
  55. return [[self alloc] initWithProviderID:providerUserInfo.providerID
  56. userID:providerUserInfo.federatedID
  57. displayName:providerUserInfo.displayName
  58. photoURL:providerUserInfo.photoURL
  59. email:providerUserInfo.email
  60. phoneNumber:providerUserInfo.phoneNumber];
  61. }
  62. - (nullable instancetype)initWithProviderID:(NSString *)providerID
  63. userID:(NSString *)userID
  64. displayName:(nullable NSString *)displayName
  65. photoURL:(nullable NSURL *)photoURL
  66. email:(nullable NSString *)email
  67. phoneNumber:(nullable NSString *)phoneNumber {
  68. self = [super init];
  69. if (self) {
  70. _providerID = [providerID copy];
  71. _userID = [userID copy];
  72. _displayName = [displayName copy];
  73. _photoURL = [photoURL copy];
  74. _email = [email copy];
  75. _phoneNumber = [phoneNumber copy];
  76. }
  77. return self;
  78. }
  79. #pragma mark - NSSecureCoding
  80. + (BOOL)supportsSecureCoding {
  81. return YES;
  82. }
  83. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  84. NSString *providerID =
  85. [aDecoder decodeObjectOfClass:[NSString class] forKey:kProviderIDCodingKey];
  86. NSString *userID = [aDecoder decodeObjectOfClass:[NSString class] forKey:kUserIDCodingKey];
  87. NSString *displayName =
  88. [aDecoder decodeObjectOfClass:[NSString class] forKey:kDisplayNameCodingKey];
  89. NSURL *photoURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:kPhotoURLCodingKey];
  90. NSString *email = [aDecoder decodeObjectOfClass:[NSString class] forKey:kEmailCodingKey];
  91. NSString *phoneNumber =
  92. [aDecoder decodeObjectOfClass:[NSString class] forKey:kPhoneNumberCodingKey];
  93. return [self initWithProviderID:providerID
  94. userID:userID
  95. displayName:displayName
  96. photoURL:photoURL
  97. email:email
  98. phoneNumber:phoneNumber];
  99. }
  100. - (void)encodeWithCoder:(NSCoder *)aCoder {
  101. [aCoder encodeObject:_providerID forKey:kProviderIDCodingKey];
  102. [aCoder encodeObject:_userID forKey:kUserIDCodingKey];
  103. [aCoder encodeObject:_displayName forKey:kDisplayNameCodingKey];
  104. [aCoder encodeObject:_photoURL forKey:kPhotoURLCodingKey];
  105. [aCoder encodeObject:_email forKey:kEmailCodingKey];
  106. [aCoder encodeObject:_phoneNumber forKey:kPhoneNumberCodingKey];
  107. }
  108. @end