[iOS] Added error message on failed authorization

https://jira.mail.ru/browse/MAPSME-15033
This commit is contained in:
Alexander Boriskov 2020-10-08 18:29:39 +03:00 committed by mpimenov
parent 560859b889
commit b8604b8fcb
13 changed files with 107 additions and 47 deletions

View file

@ -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()
}
}
}
}

View file

@ -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:

View file

@ -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])
}
})

View file

@ -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()
}
}
}
}

View file

@ -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)
}
}

View file

@ -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;

View file

@ -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]];

View file

@ -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;

View file

@ -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];
}

View file

@ -2,6 +2,7 @@
@interface MWMDefaultAlert : MWMAlert
+ (instancetype)authErrorAlertWithRetryBlock:(MWMVoidBlock)retryBlock;
+ (instancetype)routeNotFoundAlert;
+ (instancetype)routeNotFoundNoPublicTransportAlert;
+ (instancetype)routeNotFoundTooLongPedestrianAlert;

View file

@ -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")

View file

@ -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) {

View file

@ -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)
}
}
}