Skip to content

Commit 46c4321

Browse files
author
Chuan Ren
authored
Add support of not require display name on signing up (#680)
1 parent 67ca868 commit 46c4321

File tree

9 files changed

+105
-21
lines changed

9 files changed

+105
-21
lines changed

Auth/FirebaseAuthUI/FUIAuth.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error:
128128
to allow sign-up UI customizations.
129129
@param authUI The @c FUIAuth instance sending the message.
130130
@param email The email user is using for sin-in.
131+
@param requireDisplayName Whether the displayname field is required .
131132
@return an instance of @c FUIPasswordSignUpViewController subclass.
132133
*/
133134
- (FUIPasswordSignUpViewController *)passwordSignUpViewControllerForAuthUI:(FUIAuth *)authUI
134-
email:(NSString *)email;
135+
email:(NSString *)email
136+
requireDisplayName:(BOOL)requireDisplayName;
135137

136138
/** @fn passwordRecoveryViewControllerForAuthUI:email:
137139
@brief Sent to the receiver to ask for an instance of @c FUIPasswordRecoveryViewController subclass

EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,34 @@ NS_ASSUME_NONNULL_BEGIN
3636
*/
3737
@property(nonatomic, strong, readwrite, nullable) NSString *emailLink;
3838

39+
/** @fn initAuthAuthUI:signInMethod:forceSameDevice:allowNewEmailAccounts:actionCodeSetting:
40+
@brief Initializer with several configurations.
41+
@param authUI The auth UI object that this auth UI provider associate with.
42+
@param signInMethod The email sign in method, which can be password or email link.
43+
@param forceSameDevice Indicate whether for the email sign in link to be open on the same device.
44+
@param allowNewEmailAccounts Indicate whether allow sign up if the user doesn't exist.
45+
@param actionCodeSettings The action code settings for email actions.
46+
*/
47+
- (instancetype)initAuthAuthUI:(FUIAuth *)authUI
48+
signInMethod:(NSString *)signInMethod
49+
forceSameDevice:(BOOL)forceSameDevice
50+
allowNewEmailAccounts:(BOOL)allowNewEmailAccounts
51+
actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings;
52+
53+
/** @fn initAuthAuthUI:signInMethod:forceSameDevice:allowNewEmailAccounts:requireDisplayName:actionCodeSetting:
54+
@brief Initializer with several configurations.
55+
@param authUI The auth UI object that this auth UI provider associate with.
56+
@param signInMethod The email sign in method, which can be password or email link.
57+
@param forceSameDevice Indicate whether for the email sign in link to be open on the same device.
58+
@param allowNewEmailAccounts Indicate whether allow sign up if the user doesn't exist.
59+
@param requireDisplayName Indicate whether require display name when sign up.
60+
@param actionCodeSettings The action code settings for email actions.
61+
*/
3962
- (instancetype)initAuthAuthUI:(FUIAuth *)authUI
4063
signInMethod:(NSString *)signInMethod
4164
forceSameDevice:(BOOL)forceSameDevice
4265
allowNewEmailAccounts:(BOOL)allowNewEmailAccounts
66+
requireDisplayName:(BOOL)requireDisplayName
4367
actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings;
4468

4569
/** @property signInMethod.
@@ -69,6 +93,11 @@ NS_ASSUME_NONNULL_BEGIN
6993
*/
7094
@property(nonatomic, assign, readonly) BOOL allowNewEmailAccounts;
7195

96+
/** @property requireDisplayName
97+
@brief Whether signup requires display name, defaults to YES.
98+
*/
99+
@property(nonatomic, assign, readonly) BOOL requireDisplayName;
100+
72101
/** @fn signInWithPresentingViewController:
73102
@brief Signs in with email auth provider.
74103
@see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:URL:error: for method callback.

EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ - (instancetype)init {
8181
signInMethod:FIREmailPasswordAuthSignInMethod
8282
forceSameDevice:NO
8383
allowNewEmailAccounts:YES
84+
requireDisplayName:YES
8485
actionCodeSetting:[[FIRActionCodeSettings alloc] init]];
8586
}
8687

@@ -90,14 +91,29 @@ - (instancetype)initAuthAuthUI:(FUIAuth *)authUI
9091
forceSameDevice:(BOOL)forceSameDevice
9192
allowNewEmailAccounts:(BOOL)allowNewEmailAccounts
9293
actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings {
94+
return [self initAuthAuthUI:authUI
95+
signInMethod:signInMethod
96+
forceSameDevice:forceSameDevice
97+
allowNewEmailAccounts:allowNewEmailAccounts
98+
requireDisplayName:YES
99+
actionCodeSetting:actionCodeSettings];
100+
}
101+
102+
- (instancetype)initAuthAuthUI:(FUIAuth *)authUI
103+
signInMethod:(NSString *)signInMethod
104+
forceSameDevice:(BOOL)forceSameDevice
105+
allowNewEmailAccounts:(BOOL)allowNewEmailAccounts
106+
requireDisplayName:(BOOL)requireDisplayName
107+
actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings {
93108
self = [super init];
94109
if (self) {
95110
_authUI = authUI;
96111
_authUI.emailAuthProvider = self;
97112
_signInMethod = signInMethod;
98113
_forceSameDevice = forceSameDevice;
99-
_actionCodeSettings = actionCodeSettings;
100114
_allowNewEmailAccounts = allowNewEmailAccounts;
115+
_requireDisplayName = requireDisplayName;
116+
_actionCodeSettings = actionCodeSettings;
101117
}
102118
return self;
103119
}

EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ - (void)onNext:(NSString *)emailText {
194194
// New user.
195195
UIViewController *controller;
196196
if (emailAuth.allowNewEmailAccounts) {
197-
if ([delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) {
197+
if ([delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:requireDisplayName:)]) {
198198
controller = [delegate passwordSignUpViewControllerForAuthUI:self.authUI
199-
email:emailText];
199+
email:emailText
200+
requireDisplayName:emailAuth.requireDisplayName];
200201
} else {
201202
controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI
202-
email:emailText];
203+
email:emailText
204+
requireDisplayName:emailAuth.requireDisplayName];
203205
}
204206
} else {
205207
[self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)];

EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@ NS_ASSUME_NONNULL_BEGIN
5050
@param nibBundleOrNil The bundle in which to search for the nib file.
5151
@param authUI The @c FUIAuth instance that manages this view controller.
5252
@param email The email address of the user.
53+
@param requireDisplayName Whether the displayname field is required .
5354
*/
5455
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil
5556
bundle:(nullable NSBundle *)nibBundleOrNil
5657
authUI:(FUIAuth *)authUI
57-
email:(NSString *_Nullable)email NS_DESIGNATED_INITIALIZER;
58+
email:(NSString *_Nullable)email
59+
requireDisplayName:(BOOL)requireDisplayName NS_DESIGNATED_INITIALIZER;
5860

5961
/** @fn initWithAuthUI:email:
6062
@brief Convenience initializer.
6163
@param authUI The @c FUIAuth instance that manages this view controller.
6264
@param email The email address of the user.
65+
@param requireDisplayName Whether the displayname field is required .
6366
*/
6467
- (instancetype)initWithAuthUI:(FUIAuth *)authUI
65-
email:(NSString *_Nullable)email;
68+
email:(NSString *_Nullable)email
69+
requireDisplayName:(BOOL)requireDisplayName;
6670

6771
/** @fn didChangeEmail:orPassword:orUserName:
6872
@brief Should be called after any change of email, password or user name value.

EmailAuth/FirebaseEmailAuthUI/FUIPasswordSignUpViewController.m

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ @implementation FUIPasswordSignUpViewController {
7474
*/
7575
UITextField *_nameField;
7676

77+
/** @var requireDisplayName
78+
@brief Indicate weather display name field is required.
79+
*/
80+
BOOL _requireDisplayName;
81+
7782
/** @var _passwordField
7883
@brief The @c UITextField that user enters password into.
7984
*/
@@ -86,23 +91,26 @@ @implementation FUIPasswordSignUpViewController {
8691
}
8792

8893
- (instancetype)initWithAuthUI:(FUIAuth *)authUI
89-
email:(NSString *_Nullable)email {
94+
email:(NSString *_Nullable)email
95+
requireDisplayName:(BOOL)requireDisplayName {
9096
return [self initWithNibName:NSStringFromClass([self class])
9197
bundle:[FUIAuthUtils bundleNamed:FUIEmailAuthBundleName]
9298
authUI:authUI
93-
email:email];
99+
email:email
100+
requireDisplayName:requireDisplayName];
94101
}
95102

96103
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil
97104
bundle:(nullable NSBundle *)nibBundleOrNil
98105
authUI:(FUIAuth *)authUI
99-
email:(NSString *_Nullable)email {
106+
email:(NSString *_Nullable)email
107+
requireDisplayName:(BOOL)requireDisplayName {
100108
self = [super initWithNibName:nibNameOrNil
101109
bundle:nibBundleOrNil
102110
authUI:authUI];
103111
if (self) {
104112
_email = [email copy];
105-
113+
_requireDisplayName = requireDisplayName;
106114
self.title = FUILocalizedString(kStr_SignUpTitle);
107115
}
108116
return self;
@@ -233,17 +241,21 @@ - (void)textFieldDidChange {
233241
- (void)didChangeEmail:(NSString *)email
234242
orPassword:(NSString *)password
235243
orUserName:(NSString *)username {
236-
237-
BOOL enableActionButton = email.length > 0
238-
&& password.length > 0
239-
&& username.length > 0;
244+
BOOL enableActionButton = email.length > 0 && password.length > 0;
245+
if (_requireDisplayName) {
246+
enableActionButton = enableActionButton && username.length > 0;
247+
}
240248
self.navigationItem.rightBarButtonItem.enabled = enableActionButton;
241249
}
242250

243251
#pragma mark - UITableViewDataSource
244252

245253
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
246-
return 3;
254+
if (_requireDisplayName) {
255+
return 3;
256+
} else {
257+
return 2;
258+
}
247259
}
248260

249261
- (UITableViewCell *)tableView:(UITableView *)tableView
@@ -295,6 +307,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView
295307
if (@available(iOS 11.0, *)) {
296308
_passwordField.textContentType = UITextContentTypePassword;
297309
}
310+
} else if (indexPath.row == 2) {
311+
cell.label.text = FUILocalizedString(kStr_Name);
312+
cell.accessibilityIdentifier = kNameSignUpCellAccessibilityID;
313+
_nameField = cell.textField;
314+
_nameField.placeholder = FUILocalizedString(kStr_FirstAndLastName);
315+
_nameField.secureTextEntry = NO;
316+
_nameField.returnKeyType = UIReturnKeyNext;
317+
_nameField.keyboardType = UIKeyboardTypeDefault;
318+
_nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;
319+
if (@available(iOS 10.0, *)) {
320+
_nameField.textContentType = UITextContentTypeName;
321+
}
298322
}
299323
[cell.textField addTarget:self
300324
action:@selector(textFieldDidChange)

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,15 @@ + (NSArray *)getListOfIDPs:(NSArray<NSIndexPath *> *)selectedRows
381381
signInMethod:FIREmailLinkAuthSignInMethod
382382
forceSameDevice:NO
383383
allowNewEmailAccounts:YES
384+
requireDisplayName:YES
384385
actionCodeSetting:actionCodeSettings];
385386
} else {
386-
provider = [[FUIEmailAuth alloc] init];
387+
provider = [[FUIEmailAuth alloc] initAuthAuthUI:[FUIAuth defaultAuthUI]
388+
signInMethod:FIREmailPasswordAuthSignInMethod
389+
forceSameDevice:NO
390+
allowNewEmailAccounts:YES
391+
requireDisplayName:NO
392+
actionCodeSetting:[[FIRActionCodeSettings alloc] init]];
387393
}
388394
break;
389395
case kIDPGoogle:

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ - (FUIPasswordSignUpViewController *)passwordSignUpViewControllerForAuthUI:(FUIA
6969
email:(NSString *)email {
7070
return [[FUICustomPasswordSignUpViewController alloc]
7171
initWithNibName:@"FUICustomPasswordSignUpViewController"
72-
bundle:[NSBundle mainBundle]
73-
authUI:authUI
74-
email:email];
72+
bundle:[NSBundle mainBundle]
73+
authUI:authUI
74+
email:email
75+
requireDisplayName:YES];
7576
}
7677

7778
- (FUIPasswordRecoveryViewController *)

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomPasswordSignUpViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ - (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil
3333
bundle:(nullable NSBundle *)nibBundleOrNil
3434
authUI:(FUIAuth *)authUI
3535
email:(NSString *_Nullable)email {
36-
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI email:email];
36+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI email:email requireDisplayName:YES];
3737

3838
if (self) {
3939
_emailTextField.text = email;

0 commit comments

Comments
 (0)