Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Auth/FirebaseAuthUI/FUIAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ - (instancetype)init {
signInMethod:FIREmailPasswordAuthSignInMethod
forceSameDevice:NO
allowNewEmailAccounts:YES
requireDisplayName:YES
actionCodeSetting:[[FIRActionCodeSettings alloc] init]];
}

Expand All @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 33 additions & 9 deletions EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,15 @@ + (NSArray *)getListOfIDPs:(NSArray<NSIndexPath *> *)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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down