UserInfoViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2019 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 "UserInfoViewController.h"
  17. #import "FIRUser.h"
  18. #import "FIRUserInfo.h"
  19. #import "FIRUserMetadata.h"
  20. #import "StaticContentTableViewManager.h"
  21. /** @fn stringWithBool
  22. @brief Converts a boolean value to a string for display.
  23. @param boolValue the boolean value.
  24. @return The string form of the boolean value.
  25. */
  26. static NSString *stringWithBool(BOOL boolValue) {
  27. return boolValue ? @"YES" : @"NO";
  28. }
  29. /** @fn stringFromDate
  30. @brief Converts a NSDate va to a string for display.
  31. @param date The NSDate instance.
  32. @return The string form of the NSDate instance.
  33. */
  34. static NSString *stringFromDate(NSDate *date) {
  35. if (!date) {
  36. return @"nil";
  37. }
  38. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  39. dateFormatter.dateStyle = NSDateFormatterShortStyle;
  40. dateFormatter.timeStyle = NSDateFormatterShortStyle;
  41. return [dateFormatter stringFromDate:date];
  42. }
  43. @implementation UserInfoViewController {
  44. FIRUser *_user;
  45. }
  46. - (instancetype)initWithUser:(FIRUser *)user {
  47. self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
  48. if (self) {
  49. _user = user;
  50. }
  51. return self;
  52. }
  53. - (void)viewDidLoad {
  54. [super viewDidLoad];
  55. [self loadTableView];
  56. }
  57. - (void)loadTableView {
  58. NSMutableArray<StaticContentTableViewSection *> *sections = [@[
  59. [StaticContentTableViewSection sectionWithTitle:@"User" cells:@[
  60. [StaticContentTableViewCell cellWithTitle:@"anonymous" value:stringWithBool(_user.anonymous)],
  61. [StaticContentTableViewCell cellWithTitle:@"creation date"
  62. value:stringFromDate(_user.metadata.creationDate)],
  63. [StaticContentTableViewCell cellWithTitle:@"last sign in date"
  64. value:stringFromDate(_user.metadata.lastSignInDate)],
  65. [StaticContentTableViewCell cellWithTitle:@"email verified"
  66. value:stringWithBool(_user.emailVerified)],
  67. [StaticContentTableViewCell cellWithTitle:@"refresh token" value:_user.refreshToken],
  68. [StaticContentTableViewCell cellWithTitle:@"multi factor" value:[self multiFactorString]],
  69. ]]
  70. ] mutableCopy];
  71. [sections addObject:[self sectionWithUserInfo:_user]];
  72. for (id<FIRUserInfo> userInfo in _user.providerData) {
  73. [sections addObject:[self sectionWithUserInfo:userInfo]];
  74. }
  75. _tableViewManager.contents = [StaticContentTableViewContent contentWithSections:sections];
  76. }
  77. - (StaticContentTableViewSection *)sectionWithUserInfo:(id<FIRUserInfo>)userInfo {
  78. return [StaticContentTableViewSection sectionWithTitle:userInfo.providerID cells:@[
  79. [StaticContentTableViewCell cellWithTitle:@"uid" value:userInfo.uid],
  80. [StaticContentTableViewCell cellWithTitle:@"displayName" value:userInfo.displayName],
  81. [StaticContentTableViewCell cellWithTitle:@"photoURL" value:[userInfo.photoURL absoluteString]],
  82. [StaticContentTableViewCell cellWithTitle:@"email" value:userInfo.email],
  83. [StaticContentTableViewCell cellWithTitle:@"phoneNumber" value:userInfo.phoneNumber]
  84. ]];
  85. }
  86. - (IBAction)done:(id)sender {
  87. [self dismissViewControllerAnimated:YES completion:nil];
  88. }
  89. - (NSString *)multiFactorString {
  90. NSMutableString *string = [NSMutableString string];
  91. for (FIRMultiFactorInfo *info in _user.multiFactor.enrolledFactors) {
  92. [string appendString:info.displayName];
  93. [string appendString:@" "];
  94. }
  95. return string;
  96. }
  97. @end