From 12078e08c976b30664073d3c65e2954b6902e33b Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 17 May 2018 18:20:47 +0200 Subject: [PATCH 1/3] Implemented allowNewEmailAccounts --- FirebaseAuthUI/FUIAuth.h | 5 +++++ FirebaseAuthUI/FUIAuth.m | 21 ++++++++++++++----- FirebaseAuthUI/FUIEmailEntryViewController.m | 12 +++++++---- .../FUIPasswordSignInViewController.m | 17 +++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/FirebaseAuthUI/FUIAuth.h b/FirebaseAuthUI/FUIAuth.h index 8fa95b3ff2a..736aa3ba774 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, getter=allowedNewEmailAccounts) 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..d8d38738ba9 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.allowedNewEmailAccounts){ + 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..2cc1398b035 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.allowedNewEmailAccounts) { + 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 { From 6923d7c3d88689d6d8b3f0600dd16c3c2754a730 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 17 May 2018 21:15:34 +0200 Subject: [PATCH 2/3] Removed getter, Fixed Code nits --- FirebaseAuthUI/FUIAuth.h | 2 +- FirebaseAuthUI/FUIAuth.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FirebaseAuthUI/FUIAuth.h b/FirebaseAuthUI/FUIAuth.h index 736aa3ba774..6dda18424fd 100644 --- a/FirebaseAuthUI/FUIAuth.h +++ b/FirebaseAuthUI/FUIAuth.h @@ -179,7 +179,7 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error: /** @property allowNewEmailAccounts @brief Whether to allow new user sign, defaults to YES. */ -@property(nonatomic, assign, getter=allowedNewEmailAccounts) BOOL allowNewEmailAccounts; +@property(nonatomic, assign) BOOL allowNewEmailAccounts; /** @property customStringsBundle @brief Custom strings bundle supplied by the developer. Nil when there is no custom strings diff --git a/FirebaseAuthUI/FUIAuth.m b/FirebaseAuthUI/FUIAuth.m index d8d38738ba9..c0b8cb85bda 100644 --- a/FirebaseAuthUI/FUIAuth.m +++ b/FirebaseAuthUI/FUIAuth.m @@ -127,14 +127,14 @@ - (UINavigationController *)authViewController { UIViewController *controller; if (self.providers.count == 0 && !self.isSignInWithEmailHidden) { - if (self.allowedNewEmailAccounts){ + if (self.allowNewEmailAccounts) { if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) { controller = [self.delegate emailEntryViewControllerForAuthUI:self]; } else { controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self]; } } - else{ + else { if ([self.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) { controller = [self.delegate passwordSignInViewControllerForAuthUI:self email:@""]; } else { From 672abe43dd787eb43f418a616ee122cc04632b42 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 17 May 2018 21:16:29 +0200 Subject: [PATCH 3/3] removed getter --- FirebaseAuthUI/FUIEmailEntryViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseAuthUI/FUIEmailEntryViewController.m b/FirebaseAuthUI/FUIEmailEntryViewController.m index 2cc1398b035..883e06ad0f5 100644 --- a/FirebaseAuthUI/FUIEmailEntryViewController.m +++ b/FirebaseAuthUI/FUIEmailEntryViewController.m @@ -174,7 +174,7 @@ - (void)onNext:(NSString *)emailText { } else { // New user. UIViewController *controller; - if (self.authUI.allowedNewEmailAccounts) { + if (self.authUI.allowNewEmailAccounts) { if ([self.authUI.delegate respondsToSelector:@selector(passwordSignUpViewControllerForAuthUI:email:)]) { controller = [self.authUI.delegate passwordSignUpViewControllerForAuthUI:self.authUI email:emailText];