Skip to content

Commit 70b1ad5

Browse files
authored
Merge pull request #450 from najdanovicivan/allow_new_email_login
Implemented allowNewEmailAccounts
2 parents bdd3c05 + e5386e1 commit 70b1ad5

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

FirebaseAuthUI/FUIAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error:
176176
*/
177177
@property(nonatomic, assign, getter=isSignInWithEmailHidden) BOOL signInWithEmailHidden;
178178

179+
/** @property allowNewEmailAccounts
180+
@brief Whether to allow new user sign, defaults to YES.
181+
*/
182+
@property(nonatomic, assign) BOOL allowNewEmailAccounts;
183+
179184
/** @property customStringsBundle
180185
@brief Custom strings bundle supplied by the developer. Nil when there is no custom strings
181186
bundle set. In which case the default bundle will be used.

FirebaseAuthUI/FUIAuth.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "FUIAuthStrings.h"
2828
#import "FUIEmailEntryViewController.h"
2929
#import "FUIPasswordVerificationViewController.h"
30+
#import "FUIPasswordSignInViewController.h"
3031

3132
/** @var kAppNameCodingKey
3233
@brief The key used to encode the app Name for NSCoding.
@@ -104,6 +105,7 @@ + (nullable FUIAuth *)authUIWithAuth:(FIRAuth *)auth {
104105
- (instancetype)initWithAuth:(FIRAuth *)auth {
105106
self = [super init];
106107
if (self) {
108+
_allowNewEmailAccounts = YES;
107109
_auth = auth;
108110
}
109111
return self;
@@ -125,11 +127,20 @@ - (UINavigationController *)authViewController {
125127
UIViewController *controller;
126128

127129
if (self.providers.count == 0 && !self.isSignInWithEmailHidden) {
128-
if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) {
129-
controller = [self.delegate emailEntryViewControllerForAuthUI:self];
130-
} else {
131-
controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self];
132-
}
130+
if (self.allowNewEmailAccounts) {
131+
if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) {
132+
controller = [self.delegate emailEntryViewControllerForAuthUI:self];
133+
} else {
134+
controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self];
135+
}
136+
}
137+
else {
138+
if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) {
139+
controller = [self.delegate passwordSignInViewControllerForAuthUI:self email:@""];
140+
} else {
141+
controller = [[FUIPasswordSignInViewController alloc] initWithAuthUI:self email:nil];
142+
}
143+
}
133144
} else if ([self.delegate respondsToSelector:@selector(authPickerViewControllerForAuthUI:)]) {
134145
controller = [self.delegate authPickerViewControllerForAuthUI:self];
135146
} else {

FirebaseAuthUI/FUIEmailEntryViewController.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ - (void)onNext:(NSString *)emailText {
174174
} else {
175175
// New user.
176176
UIViewController *controller;
177-
if ([self.authUI.delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) {
178-
controller = [self.authUI.delegate passwordSignUpViewControllerForAuthUI:self.authUI
177+
if (self.authUI.allowNewEmailAccounts) {
178+
if ([self.authUI.delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) {
179+
controller = [self.authUI.delegate passwordSignUpViewControllerForAuthUI:self.authUI
179180
email:emailText];
180-
} else {
181-
controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI
181+
} else {
182+
controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI
182183
email:emailText];
184+
}
185+
} else {
186+
[self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)];
183187
}
184188
[self pushViewController:controller];
185189
}

FirebaseAuthUI/FUIPasswordSignInViewController.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ - (void)viewDidLoad {
9595
[self enableDynamicCellHeightForTableView:_tableView];
9696
}
9797

98+
- (void)viewWillAppear:(BOOL)animated {
99+
[super viewWillAppear:animated];
100+
101+
if (self.navigationController.viewControllers.firstObject == self) {
102+
UIBarButtonItem *cancelBarButton =
103+
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
104+
target:self
105+
action:@selector(cancelAuthorization)];
106+
self.navigationItem.leftBarButtonItem = cancelBarButton;
107+
self.navigationItem.backBarButtonItem =
108+
[[UIBarButtonItem alloc] initWithTitle:FUILocalizedString(kStr_Back)
109+
style:UIBarButtonItemStylePlain
110+
target:nil
111+
action:nil];
112+
}
113+
}
114+
98115
#pragma mark - Actions
99116

100117
- (void)signInWithDefaultValue:(NSString *)email andPassword:(NSString *)password {

0 commit comments

Comments
 (0)