From b8604b8fcb7e52bf7a931ca6c3bb200c346f9213 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Thu, 8 Oct 2020 18:29:39 +0300 Subject: [PATCH] [iOS] Added error message on failed authorization https://jira.mail.ru/browse/MAPSME-15033 --- .../Catalog/CatalogWebViewController.swift | 14 ++-- .../BMCView/BMCViewController.swift | 13 +++- .../BookmarksSharingViewController.swift | 10 ++- .../Sharing/EditOnWebViewController.swift | 10 ++- .../UIViewController+Authorization.swift | 13 ++-- .../AlertController/MWMAlertViewController.h | 1 + .../AlertController/MWMAlertViewController.mm | 5 ++ .../Classes/CustomAlert/BaseAlert/MWMAlert.h | 1 + .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 5 ++ .../DefaultAlert/MWMDefaultAlert.h | 1 + .../DefaultAlert/MWMDefaultAlert.mm | 9 +++ .../UI/Settings/MWMSettingsViewController.mm | 8 ++- .../Subscription/SubscriptionInteractor.swift | 64 +++++++++++-------- 13 files changed, 107 insertions(+), 47 deletions(-) diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index a1427e4e28..b4dd085a98 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -263,11 +263,11 @@ final class CatalogWebViewController: WebViewController { self?.loadingIndicator.stopAnimating() case .needAuth: if let s = self, let navBar = s.navigationController?.navigationBar { - s.signup(anchor: navBar, source: .guideCatalogue, onComplete: { - if $0 { + s.signup(anchor: navBar, source: .guideCatalogue, onComplete: { result in + if result == .succes { s.reloadFromOrigin() s.handlePendingTransactions(completion: completion) - } else { + } else if result == .error { MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"), text: L("failed_purchase_support_message")) completion(false) @@ -327,10 +327,14 @@ final class CatalogWebViewController: WebViewController { switch status { case .needAuth: if let s = self, let navBar = s.navigationController?.navigationBar { - s.signup(anchor: navBar, source: .guideCatalogue) { - if $0 { + s.signup(anchor: navBar, source: .guideCatalogue) { result in + if result == .succes { s.reloadFromOrigin() s.download() + } else if result == .error { + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + s.download() + } } } } diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index bb03ab9913..863dde4e57 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -315,10 +315,17 @@ extension BMCViewController: BMCPermissionsCellDelegate { switch permission { case .signup: viewModel.pendingPermission(isPending: true) - signup(anchor: anchor, source: .bookmarksBackup, onComplete: { [viewModel] success in - viewModel!.grant(permission: success ? .backup : nil) - if !success { + signup(anchor: anchor, source: .bookmarksBackup, onComplete: { [weak self, viewModel] result in + if result == .succes { + viewModel!.grant(permission: .backup) + } else if result == .cancel { + viewModel?.pendingPermission(isPending: false) + } else if result == .error { Statistics.logEvent(kStatBookmarksAuthRequestError) + viewModel?.pendingPermission(isPending: false) + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + self?.permissionAction(permission: permission, anchor: anchor) + } } }) case .backup: diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift index 7585de0bbb..29beb1a040 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift @@ -296,10 +296,14 @@ final class BookmarksSharingViewController: MWMTableViewController { private func performAfterValidation(anchor: UIView, action: @escaping MWMVoidBlock) { if FrameworkHelper.isNetworkConnected() { - signup(anchor: anchor, source: .exportBookmarks, onComplete: { success in - if success { + signup(anchor: anchor, source: .exportBookmarks, onComplete: {[weak self] result in + if result == .succes { action() - } else { + + } else if result == .error { + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + self?.performAfterValidation(anchor: anchor, action: action) + } Statistics.logEvent(kStatSharingOptionsError, withParameters: [kStatError : 1]) } }) diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift index 851473478c..e69b5a65d0 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift @@ -131,9 +131,13 @@ final class EditOnWebViewController: MWMViewController { } private func authError() { - signup(anchor: sendMeLinkButton, source: .exportBookmarks) { - if ($0) { - self.uploadCategory() + signup(anchor: sendMeLinkButton, source: .exportBookmarks) {[weak self] result in + if result == .succes { + self?.uploadCategory() + } else if result == .error { + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + self?.authError() + } } } } diff --git a/iphone/Maps/Categories/UIViewController+Authorization.swift b/iphone/Maps/Categories/UIViewController+Authorization.swift index 03dbf78713..62487c75fa 100644 --- a/iphone/Maps/Categories/UIViewController+Authorization.swift +++ b/iphone/Maps/Categories/UIViewController+Authorization.swift @@ -1,13 +1,18 @@ +@objc enum AuthorizationResult: Int { + case succes + case error + case cancel +} extension UIViewController { - @objc func signup(anchor: UIView, source: AuthorizationSource, onComplete: @escaping (Bool) -> Void) { + @objc func signup(anchor: UIView, source: AuthorizationSource, onComplete: @escaping (AuthorizationResult) -> Void) { if User.isAuthenticated() { - onComplete(true) + onComplete(.succes) } else { let authVC = AuthorizationViewController(popoverSourceView: anchor, source: source, permittedArrowDirections: .any, - successHandler: { _ in onComplete(true) }, - errorHandler: { _ in onComplete(false) }) + successHandler: { _ in onComplete(.succes) }, + errorHandler: { onComplete($0 == .passportError ? .error : .cancel) }) present(authVC, animated: true, completion: nil) } } diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 2a135edfa0..04bda952ee 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -10,6 +10,7 @@ - (nonnull instancetype)initWithViewController:(nonnull UIViewController *)viewController; - (void)presentRateAlert; +- (void)presentAuthErrorAlertWithRetryBlock:(nonnull MWMVoidBlock)retryBlock; - (void)presentPoint2PointAlertWithOkBlock:(nonnull MWMVoidBlock)okBlock needToRebuild:(BOOL)needToRebuild; - (void)presentRoutingDisclaimerAlertWithOkBlock:(nonnull nonnull MWMVoidBlock)block; - (void)presentDisabledLocationAlert; diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index 05a4a142d0..efdceeb4ce 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -50,6 +50,11 @@ static NSString *const kAlertControllerNibIdentifier = @"MWMAlertViewController" - (void)presentRateAlert { [self displayAlert:[MWMAlert rateAlert]]; } + +- (void)presentAuthErrorAlertWithRetryBlock:(nonnull MWMVoidBlock)retryBlock { + [self displayAlert:[MWMAlert authErrorAlertWithRetryBlock:retryBlock]]; +} + - (void)presentLocationAlertWithCancelBlock:(MWMVoidBlock)cancelBlock { if (![MapViewController sharedController].welcomePageController) [self displayAlert:[MWMAlert locationAlertWithCancelBlock:cancelBlock]]; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h index e8e900f887..beb7e61457 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h @@ -4,6 +4,7 @@ @property(weak, nonatomic) MWMAlertViewController *alertController; + (MWMAlert *)rateAlert; ++ (MWMAlert *)authErrorAlertWithRetryBlock:(MWMVoidBlock)retryBlock; + (MWMAlert *)locationAlertWithCancelBlock:(MWMVoidBlock)cancelBlock; + (MWMAlert *)routingDisclaimerAlertWithOkBlock:(MWMVoidBlock)block; + (MWMAlert *)disabledLocationAlert; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index cae0270922..b3dea24c7b 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -16,6 +16,11 @@ + (MWMAlert *)rateAlert { return [MWMRateAlert alert]; } + ++ (MWMAlert *)authErrorAlertWithRetryBlock:(MWMVoidBlock)retryBlock { + return [MWMDefaultAlert authErrorAlertWithRetryBlock:retryBlock]; +} + + (MWMAlert *)locationAlertWithCancelBlock:(MWMVoidBlock)cancelBlock { return [MWMLocationAlert alertWithCancelBlock:cancelBlock]; } diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h index 7892f84b04..599e8fa15e 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h @@ -2,6 +2,7 @@ @interface MWMDefaultAlert : MWMAlert ++ (instancetype)authErrorAlertWithRetryBlock:(MWMVoidBlock)retryBlock; + (instancetype)routeNotFoundAlert; + (instancetype)routeNotFoundNoPublicTransportAlert; + (instancetype)routeNotFoundTooLongPedestrianAlert; diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm index a7e1061f86..3ec07d8c18 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm @@ -25,6 +25,15 @@ static NSString *const kDefaultAlertNibName = @"MWMDefaultAlert"; @implementation MWMDefaultAlert ++ (instancetype)authErrorAlertWithRetryBlock:(MWMVoidBlock)retryBlock { + return [self defaultAlertWithTitle:L(@"profile_authorization_error") + message:nil + rightButtonTitle:L(@"downloader_retry") + leftButtonTitle:L(@"cancel") + rightButtonAction:retryBlock + statisticsEvent:@"Authorization Error Alert"]; +} + + (instancetype)routeFileNotExistAlert { return [self defaultAlertWithTitle:L(@"dialog_routing_download_files") message:L(@"dialog_routing_download_and_update_all") diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm index a04e3416cc..bad2d9705f 100644 --- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm @@ -323,9 +323,13 @@ using namespace power_management; __weak auto s = self; [self signupWithAnchor:self.restoreSubscriptionCell.progress source:AuthorizationSourceSubscription - onComplete:^(BOOL success) { - if (success) { + onComplete:^(AuthorizationResult result) { + if (result == AuthorizationResultSucces) { [s restoreSubscription]; + } else if (result == AuthorizationResultError) { + [MWMAlertViewController.activeAlertController presentAuthErrorAlertWithRetryBlock:^{ + [s tableView:tableView didSelectRowAtIndexPath:indexPath]; + }]; } }]; } else if (cell == self.manageSubscriptionsCell) { diff --git a/iphone/Maps/UI/Subscription/SubscriptionInteractor.swift b/iphone/Maps/UI/Subscription/SubscriptionInteractor.swift index ac62d18523..dbbe963c30 100644 --- a/iphone/Maps/UI/Subscription/SubscriptionInteractor.swift +++ b/iphone/Maps/UI/Subscription/SubscriptionInteractor.swift @@ -28,19 +28,24 @@ extension SubscriptionInteractor: SubscriptionInteractorProtocol { func purchase(anchor: UIView, subscription: ISubscription, trial: Bool) { self.trial = trial subscriptionManager.addListener(self) - viewController?.signup(anchor: anchor, source: .subscription) { [weak self] success in - guard success else { return } - self?.presenter.isLoadingHidden = false - self?.bookmarksManager.ping { success in - guard success else { - self?.presenter.isLoadingHidden = true - let errorDialog = SubscriptionFailViewController { [weak self] in - self?.presenter.onCancel() + viewController?.signup(anchor: anchor, source: .subscription) { [weak self] result in + if result == .succes { + self?.presenter.isLoadingHidden = false + self?.bookmarksManager.ping { success in + guard success else { + self?.presenter.isLoadingHidden = true + let errorDialog = SubscriptionFailViewController { [weak self] in + self?.presenter.onCancel() + } + self?.viewController?.present(errorDialog, animated: true) + return } - self?.viewController?.present(errorDialog, animated: true) - return + self?.subscriptionManager.subscribe(to: subscription) + } + } else if result == .error { + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + self?.purchase(anchor: anchor, subscription: subscription, trial: trial) } - self?.subscriptionManager.subscribe(to: subscription) } } } @@ -48,23 +53,28 @@ extension SubscriptionInteractor: SubscriptionInteractorProtocol { func restore(anchor: UIView) { trial = false subscriptionManager.addListener(self) - viewController?.signup(anchor: anchor, source: .subscription) { [weak self] success in - guard success else { return } - self?.presenter.isLoadingHidden = false - self?.subscriptionManager.restore { result, _ in - self?.presenter.isLoadingHidden = true - let alertText: String - switch result { - case .valid: - alertText = L("restore_success_alert") - case .notValid: - alertText = L("restore_no_subscription_alert") - case .serverError, .authError: - alertText = L("restore_error_alert") - @unknown default: - fatalError() + viewController?.signup(anchor: anchor, source: .subscription) { [weak self] result in + if result == .succes { + self?.presenter.isLoadingHidden = false + self?.subscriptionManager.restore { result, _ in + self?.presenter.isLoadingHidden = true + let alertText: String + switch result { + case .valid: + alertText = L("restore_success_alert") + case .notValid: + alertText = L("restore_no_subscription_alert") + case .serverError, .authError: + alertText = L("restore_error_alert") + @unknown default: + fatalError() + } + MWMAlertViewController.activeAlert().presentInfoAlert(L("restore_subscription"), text: alertText) + } + } else if result == .error { + MWMAlertViewController.activeAlert().presentAuthErrorAlert { + self?.restore(anchor: anchor) } - MWMAlertViewController.activeAlert().presentInfoAlert(L("restore_subscription"), text: alertText) } } }