diff --git a/Auth/FirebaseAuthUI/FUIAuth.h b/Auth/FirebaseAuthUI/FUIAuth.h index d724b3c9bf2..df8f3183afd 100644 --- a/Auth/FirebaseAuthUI/FUIAuth.h +++ b/Auth/FirebaseAuthUI/FUIAuth.h @@ -128,10 +128,12 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error: to allow sign-up UI customizations. @param authUI The @c FUIAuth instance sending the message. @param email The email user is using for sin-in. + @param requireDisplayName Whether the displayname field is required . @return an instance of @c FUIPasswordSignUpViewController subclass. */ - (FUIPasswordSignUpViewController *)passwordSignUpViewControllerForAuthUI:(FUIAuth *)authUI - email:(NSString *)email; + email:(NSString *)email + requireDisplayName:(BOOL)requireDisplayName; /** @fn passwordRecoveryViewControllerForAuthUI:email: @brief Sent to the receiver to ask for an instance of @c FUIPasswordRecoveryViewController subclass diff --git a/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h b/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h index c04ee3408b2..35591d78ac3 100644 --- a/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h +++ b/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h @@ -36,10 +36,34 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, strong, readwrite, nullable) NSString *emailLink; +/** @fn initAuthAuthUI:signInMethod:forceSameDevice:allowNewEmailAccounts:actionCodeSetting: + @brief Initializer with several configurations. + @param authUI The auth UI object that this auth UI provider associate with. + @param signInMethod The email sign in method, which can be password or email link. + @param forceSameDevice Indicate whether for the email sign in link to be open on the same device. + @param allowNewEmailAccounts Indicate whether allow sign up if the user doesn't exist. + @param actionCodeSettings The action code settings for email actions. + */ +- (instancetype)initAuthAuthUI:(FUIAuth *)authUI + signInMethod:(NSString *)signInMethod + forceSameDevice:(BOOL)forceSameDevice + allowNewEmailAccounts:(BOOL)allowNewEmailAccounts + actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings; + +/** @fn initAuthAuthUI:signInMethod:forceSameDevice:allowNewEmailAccounts:requireDisplayName:actionCodeSetting: + @brief Initializer with several configurations. + @param authUI The auth UI object that this auth UI provider associate with. + @param signInMethod The email sign in method, which can be password or email link. + @param forceSameDevice Indicate whether for the email sign in link to be open on the same device. + @param allowNewEmailAccounts Indicate whether allow sign up if the user doesn't exist. + @param requireDisplayName Indicate whether require display name when sign up. + @param actionCodeSettings The action code settings for email actions. + */ - (instancetype)initAuthAuthUI:(FUIAuth *)authUI signInMethod:(NSString *)signInMethod forceSameDevice:(BOOL)forceSameDevice allowNewEmailAccounts:(BOOL)allowNewEmailAccounts + requireDisplayName:(BOOL)requireDisplayName actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings; /** @property signInMethod. @@ -69,6 +93,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, assign, readonly) BOOL allowNewEmailAccounts; +/** @property requireDisplayName + @brief Whether signup requires display name, defaults to YES. + */ +@property(nonatomic, assign, readonly) BOOL requireDisplayName; + /** @fn signInWithPresentingViewController: @brief Signs in with email auth provider. @see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:URL:error: for method callback. diff --git a/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m b/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m index a14dc49b2b5..598c1f392e5 100644 --- a/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m +++ b/EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m @@ -81,6 +81,7 @@ - (instancetype)init { signInMethod:FIREmailPasswordAuthSignInMethod forceSameDevice:NO allowNewEmailAccounts:YES + requireDisplayName:YES actionCodeSetting:[[FIRActionCodeSettings alloc] init]]; } @@ -90,14 +91,29 @@ - (instancetype)initAuthAuthUI:(FUIAuth *)authUI forceSameDevice:(BOOL)forceSameDevice allowNewEmailAccounts:(BOOL)allowNewEmailAccounts actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings { + return [self initAuthAuthUI:authUI + signInMethod:signInMethod + forceSameDevice:forceSameDevice + allowNewEmailAccounts:allowNewEmailAccounts + requireDisplayName:YES + actionCodeSetting:actionCodeSettings]; +} + +- (instancetype)initAuthAuthUI:(FUIAuth *)authUI + signInMethod:(NSString *)signInMethod + forceSameDevice:(BOOL)forceSameDevice + allowNewEmailAccounts:(BOOL)allowNewEmailAccounts + requireDisplayName:(BOOL)requireDisplayName + actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings { self = [super init]; if (self) { _authUI = authUI; _authUI.emailAuthProvider = self; _signInMethod = signInMethod; _forceSameDevice = forceSameDevice; - _actionCodeSettings = actionCodeSettings; _allowNewEmailAccounts = allowNewEmailAccounts; + _requireDisplayName = requireDisplayName; + _actionCodeSettings = actionCodeSettings; } return self; } diff --git a/EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m b/EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m index cff6bc0e19c..a4bcbd051a8 100755 --- a/EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m +++ b/EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m @@ -194,12 +194,14 @@ - (void)onNext:(NSString *)emailText { // New user. UIViewController *controller; if (emailAuth.allowNewEmailAccounts) { - if ([delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) { + if ([delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:requireDisplayName:)]) { controller = [delegate passwordSignUpViewControllerForAuthUI:self.authUI - email:emailText]; + email:emailText + requireDisplayName:emailAuth.requireDisplayName]; } else { controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI - email:emailText]; + email:emailText + requireDisplayName:emailAuth.requireDisplayName]; } } else { [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; diff --git a/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.h b/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.h index 6f96744298d..db0abddb5c4 100644 --- a/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.h +++ b/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.h @@ -50,19 +50,23 @@ NS_ASSUME_NONNULL_BEGIN @param nibBundleOrNil The bundle in which to search for the nib file. @param authUI The @c FUIAuth instance that manages this view controller. @param email The email address of the user. + @param requireDisplayName Whether the displayname field is required . */ - (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil authUI:(FUIAuth *)authUI - email:(NSString *_Nullable)email NS_DESIGNATED_INITIALIZER; + email:(NSString *_Nullable)email + requireDisplayName:(BOOL)requireDisplayName NS_DESIGNATED_INITIALIZER; /** @fn initWithAuthUI:email: @brief Convenience initializer. @param authUI The @c FUIAuth instance that manages this view controller. @param email The email address of the user. + @param requireDisplayName Whether the displayname field is required . */ - (instancetype)initWithAuthUI:(FUIAuth *)authUI - email:(NSString *_Nullable)email; + email:(NSString *_Nullable)email + requireDisplayName:(BOOL)requireDisplayName; /** @fn didChangeEmail:orPassword:orUserName: @brief Should be called after any change of email, password or user name value. diff --git a/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m b/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m index 39932b5698c..82fe739cdb0 100755 --- a/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m +++ b/EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m @@ -74,6 +74,11 @@ @implementation FUIPasswordSignUpViewController { */ UITextField *_nameField; + /** @var requireDisplayName + @brief Indicate weather display name field is required. + */ + BOOL _requireDisplayName; + /** @var _passwordField @brief The @c UITextField that user enters password into. */ @@ -86,23 +91,26 @@ @implementation FUIPasswordSignUpViewController { } - (instancetype)initWithAuthUI:(FUIAuth *)authUI - email:(NSString *_Nullable)email { + email:(NSString *_Nullable)email + requireDisplayName:(BOOL)requireDisplayName { return [self initWithNibName:NSStringFromClass([self class]) bundle:[FUIAuthUtils bundleNamed:FUIEmailAuthBundleName] authUI:authUI - email:email]; + email:email + requireDisplayName:requireDisplayName]; } - (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil authUI:(FUIAuth *)authUI - email:(NSString *_Nullable)email { + email:(NSString *_Nullable)email + requireDisplayName:(BOOL)requireDisplayName { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI]; if (self) { _email = [email copy]; - + _requireDisplayName = requireDisplayName; self.title = FUILocalizedString(kStr_SignUpTitle); } return self; @@ -233,17 +241,21 @@ - (void)textFieldDidChange { - (void)didChangeEmail:(NSString *)email orPassword:(NSString *)password orUserName:(NSString *)username { - - BOOL enableActionButton = email.length > 0 - && password.length > 0 - && username.length > 0; + BOOL enableActionButton = email.length > 0 && password.length > 0; + if (_requireDisplayName) { + enableActionButton = enableActionButton && username.length > 0; + } self.navigationItem.rightBarButtonItem.enabled = enableActionButton; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 3; + if (_requireDisplayName) { + return 3; + } else { + return 2; + } } - (UITableViewCell *)tableView:(UITableView *)tableView @@ -295,6 +307,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView if (@available(iOS 11.0, *)) { _passwordField.textContentType = UITextContentTypePassword; } + } else if (indexPath.row == 2) { + cell.label.text = FUILocalizedString(kStr_Name); + cell.accessibilityIdentifier = kNameSignUpCellAccessibilityID; + _nameField = cell.textField; + _nameField.placeholder = FUILocalizedString(kStr_FirstAndLastName); + _nameField.secureTextEntry = NO; + _nameField.returnKeyType = UIReturnKeyNext; + _nameField.keyboardType = UIKeyboardTypeDefault; + _nameField.autocapitalizationType = UITextAutocapitalizationTypeWords; + if (@available(iOS 10.0, *)) { + _nameField.textContentType = UITextContentTypeName; + } } [cell.textField addTarget:self action:@selector(textFieldDidChange) diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m index bf00d123207..7f22940f1fa 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m @@ -381,9 +381,15 @@ + (NSArray *)getListOfIDPs:(NSArray *)selectedRows signInMethod:FIREmailLinkAuthSignInMethod forceSameDevice:NO allowNewEmailAccounts:YES + requireDisplayName:YES actionCodeSetting:actionCodeSettings]; } else { - provider = [[FUIEmailAuth alloc] init]; + provider = [[FUIEmailAuth alloc] initAuthAuthUI:[FUIAuth defaultAuthUI] + signInMethod:FIREmailPasswordAuthSignInMethod + forceSameDevice:NO + allowNewEmailAccounts:YES + requireDisplayName:NO + actionCodeSetting:[[FIRActionCodeSettings alloc] init]]; } break; case kIDPGoogle: diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m index 6778431d790..606fbe6eb93 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m @@ -69,9 +69,10 @@ - (FUIPasswordSignUpViewController *)passwordSignUpViewControllerForAuthUI:(FUIA email:(NSString *)email { return [[FUICustomPasswordSignUpViewController alloc] initWithNibName:@"FUICustomPasswordSignUpViewController" - bundle:[NSBundle mainBundle] - authUI:authUI - email:email]; + bundle:[NSBundle mainBundle] + authUI:authUI + email:email + requireDisplayName:YES]; } - (FUIPasswordRecoveryViewController *) diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomPasswordSignUpViewController.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomPasswordSignUpViewController.m index 494775ae4e9..7d9ac4ea395 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomPasswordSignUpViewController.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomPasswordSignUpViewController.m @@ -33,7 +33,7 @@ - (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil authUI:(FUIAuth *)authUI email:(NSString *_Nullable)email { - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI email:email]; + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI email:email requireDisplayName:YES]; if (self) { _emailTextField.text = email;