diff --git a/FirebaseAuthUI/FUIAuth.h b/FirebaseAuthUI/FUIAuth.h index 8fa95b3ff2a..6dda18424fd 100644 --- a/FirebaseAuthUI/FUIAuth.h +++ b/FirebaseAuthUI/FUIAuth.h @@ -176,6 +176,11 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error: */ @property(nonatomic, assign, getter=isSignInWithEmailHidden) BOOL signInWithEmailHidden; +/** @property allowNewEmailAccounts + @brief Whether to allow new user sign, defaults to YES. + */ +@property(nonatomic, assign) BOOL allowNewEmailAccounts; + /** @property customStringsBundle @brief Custom strings bundle supplied by the developer. Nil when there is no custom strings bundle set. In which case the default bundle will be used. diff --git a/FirebaseAuthUI/FUIAuth.m b/FirebaseAuthUI/FUIAuth.m index d73700a19d5..c0b8cb85bda 100644 --- a/FirebaseAuthUI/FUIAuth.m +++ b/FirebaseAuthUI/FUIAuth.m @@ -27,6 +27,7 @@ #import "FUIAuthStrings.h" #import "FUIEmailEntryViewController.h" #import "FUIPasswordVerificationViewController.h" +#import "FUIPasswordSignInViewController.h" /** @var kAppNameCodingKey @brief The key used to encode the app Name for NSCoding. @@ -104,6 +105,7 @@ + (nullable FUIAuth *)authUIWithAuth:(FIRAuth *)auth { - (instancetype)initWithAuth:(FIRAuth *)auth { self = [super init]; if (self) { + _allowNewEmailAccounts = YES; _auth = auth; } return self; @@ -125,11 +127,20 @@ - (UINavigationController *)authViewController { UIViewController *controller; if (self.providers.count == 0 && !self.isSignInWithEmailHidden) { - if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) { - controller = [self.delegate emailEntryViewControllerForAuthUI:self]; - } else { - controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self]; - } + if (self.allowNewEmailAccounts) { + if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) { + controller = [self.delegate emailEntryViewControllerForAuthUI:self]; + } else { + controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self]; + } + } + else { + if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) { + controller = [self.delegate passwordSignInViewControllerForAuthUI:self email:@""]; + } else { + controller = [[FUIPasswordSignInViewController alloc] initWithAuthUI:self email:nil]; + } + } } else if ([self.delegate respondsToSelector:@selector(authPickerViewControllerForAuthUI:)]) { controller = [self.delegate authPickerViewControllerForAuthUI:self]; } else { diff --git a/FirebaseAuthUI/FUIEmailEntryViewController.m b/FirebaseAuthUI/FUIEmailEntryViewController.m index d115e1efca3..883e06ad0f5 100644 --- a/FirebaseAuthUI/FUIEmailEntryViewController.m +++ b/FirebaseAuthUI/FUIEmailEntryViewController.m @@ -174,12 +174,16 @@ - (void)onNext:(NSString *)emailText { } else { // New user. UIViewController *controller; - if ([self.authUI.delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) { - controller = [self.authUI.delegate passwordSignUpViewControllerForAuthUI:self.authUI + if (self.authUI.allowNewEmailAccounts) { + if ([self.authUI.delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) { + controller = [self.authUI.delegate passwordSignUpViewControllerForAuthUI:self.authUI email:emailText]; - } else { - controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI + } else { + controller = [[FUIPasswordSignUpViewController alloc] initWithAuthUI:self.authUI email:emailText]; + } + } else { + [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; } [self pushViewController:controller]; } diff --git a/FirebaseAuthUI/FUIPasswordSignInViewController.m b/FirebaseAuthUI/FUIPasswordSignInViewController.m index 7e8d6525217..e080e00144e 100644 --- a/FirebaseAuthUI/FUIPasswordSignInViewController.m +++ b/FirebaseAuthUI/FUIPasswordSignInViewController.m @@ -95,6 +95,23 @@ - (void)viewDidLoad { [self enableDynamicCellHeightForTableView:_tableView]; } +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + if (self.navigationController.viewControllers.firstObject == self) { + UIBarButtonItem *cancelBarButton = + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel + target:self + action:@selector(cancelAuthorization)]; + self.navigationItem.leftBarButtonItem = cancelBarButton; + self.navigationItem.backBarButtonItem = + [[UIBarButtonItem alloc] initWithTitle:FUILocalizedString(kStr_Back) + style:UIBarButtonItemStylePlain + target:nil + action:nil]; + } +} + #pragma mark - Actions - (void)signInWithDefaultValue:(NSString *)email andPassword:(NSString *)password {