UserInfoViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "UserInfoViewController.h"
  17. #import "FIRUser_Internal.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:@"emailVerified"
  66. value:stringWithBool(_user.emailVerified)],
  67. [StaticContentTableViewCell cellWithTitle:@"refreshToken" value:_user.refreshToken],
  68. ]]
  69. ] mutableCopy];
  70. [sections addObject:[self sectionWithUserInfo:_user]];
  71. for (id<FIRUserInfo> userInfo in _user.providerData) {
  72. [sections addObject:[self sectionWithUserInfo:userInfo]];
  73. }
  74. _tableViewManager.contents = [StaticContentTableViewContent contentWithSections:sections];
  75. }
  76. - (StaticContentTableViewSection *)sectionWithUserInfo:(id<FIRUserInfo>)userInfo {
  77. return [StaticContentTableViewSection sectionWithTitle:userInfo.providerID cells:@[
  78. [StaticContentTableViewCell cellWithTitle:@"uid" value:userInfo.uid],
  79. [StaticContentTableViewCell cellWithTitle:@"displayName" value:userInfo.displayName],
  80. [StaticContentTableViewCell cellWithTitle:@"photoURL" value:[userInfo.photoURL absoluteString]],
  81. [StaticContentTableViewCell cellWithTitle:@"email" value:userInfo.email],
  82. [StaticContentTableViewCell cellWithTitle:@"phoneNumber" value:userInfo.phoneNumber]
  83. ]];
  84. }
  85. - (IBAction)done:(id)sender {
  86. [self dismissViewControllerAnimated:YES completion:nil];
  87. }
  88. @end