diff --git a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj index e75373ec88..296b5dae63 100644 --- a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj +++ b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj @@ -51,6 +51,8 @@ 47D9019923AC236100D9364C /* MWMMapUpdateInfo+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = 47D9019723AC236100D9364C /* MWMMapUpdateInfo+Core.h */; settings = {ATTRIBUTES = (Public, ); }; }; 47E8163623B1889C008FD836 /* MWMStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 47E8163423B1889B008FD836 /* MWMStorage.mm */; }; 47E8163723B188D3008FD836 /* MWMStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 47E8163523B1889B008FD836 /* MWMStorage.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 47E8164023B2B98F008FD836 /* MWMUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 47E8163E23B2B98F008FD836 /* MWMUser.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 47E8164123B2B98F008FD836 /* MWMUser.mm in Sources */ = {isa = PBXBuildFile; fileRef = 47E8163F23B2B98F008FD836 /* MWMUser.mm */; }; 47EEAFF42350CEDB005CF316 /* AppInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 47EEAFF22350CEDA005CF316 /* AppInfo.mm */; }; 47EEAFF62350CF48005CF316 /* AppInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 47EEAFF32350CEDB005CF316 /* AppInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 47EEAFF72350D060005CF316 /* MWMCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 47EEAFF52350CEF6005CF316 /* MWMCommon.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -123,6 +125,8 @@ 47D9019723AC236100D9364C /* MWMMapUpdateInfo+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MWMMapUpdateInfo+Core.h"; sourceTree = ""; }; 47E8163423B1889B008FD836 /* MWMStorage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMStorage.mm; sourceTree = ""; }; 47E8163523B1889B008FD836 /* MWMStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMStorage.h; sourceTree = ""; }; + 47E8163E23B2B98F008FD836 /* MWMUser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMUser.h; sourceTree = ""; }; + 47E8163F23B2B98F008FD836 /* MWMUser.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMUser.mm; sourceTree = ""; }; 47EEAFF22350CEDA005CF316 /* AppInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = AppInfo.mm; sourceTree = ""; }; 47EEAFF32350CEDB005CF316 /* AppInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppInfo.h; sourceTree = ""; }; 47EEAFF52350CEF6005CF316 /* MWMCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCommon.h; sourceTree = ""; }; @@ -185,6 +189,7 @@ 470015F12342509C00EBF03D /* CoreApi */ = { isa = PBXGroup; children = ( + 47E8163D23B2B97A008FD836 /* User */, 47F4F1F623A333280022FD56 /* Storage */, 993F54ED237C5D1000545511 /* Promo */, 9957FAE5237AE59C00855F48 /* Logger */, @@ -319,6 +324,15 @@ path = Search; sourceTree = ""; }; + 47E8163D23B2B97A008FD836 /* User */ = { + isa = PBXGroup; + children = ( + 47E8163E23B2B98F008FD836 /* MWMUser.h */, + 47E8163F23B2B98F008FD836 /* MWMUser.mm */, + ); + path = User; + sourceTree = ""; + }; 47F4F1F623A333280022FD56 /* Storage */ = { isa = PBXGroup; children = ( @@ -408,6 +422,7 @@ 993F54F5237C5D1100545511 /* PromoAfterBookingCampaignAdapter.h in Headers */, 479834F223426CCC00724D1E /* MWMTag+Convenience.h in Headers */, 479F704F234FB60400011E2E /* MWMCatalogObserver.h in Headers */, + 47E8164023B2B98F008FD836 /* MWMUser.h in Headers */, 47EEAFF72350D060005CF316 /* MWMCommon.h in Headers */, 47D9019523AC22E500D9364C /* MWMMapUpdateInfo.h in Headers */, 9957FADB237ACB1100855F48 /* DeepLinkSearchData.h in Headers */, @@ -524,6 +539,7 @@ 479F7047234F774100011E2E /* MWMFrameworkHelper.mm in Sources */, 470016072342541100EBF03D /* MWMTag.m in Sources */, 47D9019623AC22E500D9364C /* MWMMapUpdateInfo.mm in Sources */, + 47E8164123B2B98F008FD836 /* MWMUser.mm in Sources */, 471AB98E23AB925D00F56D49 /* MWMMapSearchResult.mm in Sources */, 479834EA2342697400724D1E /* MWMTag+Convenience.mm in Sources */, 47C637D62354AEBE00E12DE0 /* MWMTrafficManager.mm in Sources */, diff --git a/iphone/CoreApi/CoreApi/CoreApi-swift.h b/iphone/CoreApi/CoreApi/CoreApi-swift.h index 1743060dff..e9caebbcf9 100644 --- a/iphone/CoreApi/CoreApi/CoreApi-swift.h +++ b/iphone/CoreApi/CoreApi/CoreApi-swift.h @@ -19,6 +19,7 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[]; #import #import #import +#import #import #import #import diff --git a/iphone/CoreApi/CoreApi/CoreApi.h b/iphone/CoreApi/CoreApi/CoreApi.h index e9e70088e0..2efe732239 100644 --- a/iphone/CoreApi/CoreApi/CoreApi.h +++ b/iphone/CoreApi/CoreApi/CoreApi.h @@ -15,8 +15,10 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[]; #import #import #import +#import #import #import #import #import +#import #import diff --git a/iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.h b/iphone/CoreApi/CoreApi/User/MWMUser.h similarity index 53% rename from iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.h rename to iphone/CoreApi/CoreApi/User/MWMUser.h index 75f7b95aa0..571242efe1 100644 --- a/iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.h +++ b/iphone/CoreApi/CoreApi/User/MWMUser.h @@ -1,33 +1,36 @@ +#import + +#import "MWMTypes.h" + typedef NS_ENUM(NSInteger, MWMSocialTokenType) { MWMSocialTokenTypeGoogle, MWMSocialTokenTypeFacebook, MWMSocialTokenTypePhone -}; +} NS_SWIFT_NAME(SocialTokenType); typedef NS_ENUM(NSInteger, MWMAuthorizationSource) { MWMAuthorizationSourceUGC, MWMAuthorizationSourceBookmarks -}; +} NS_SWIFT_NAME(AuthorizationSource); -typedef NS_ENUM(NSInteger, MWMAuthorizationError) { - MWMAuthorizationErrorCancelled, - MWMAuthorizationErrorPassportError -}; +NS_ASSUME_NONNULL_BEGIN -typedef void (^MWMAuthorizationCompleteBlock)(BOOL); +NS_SWIFT_NAME(User) +@interface MWMUser : NSObject -@interface MWMAuthorizationViewModel : NSObject - -+ (NSURL * _Nullable)phoneAuthURL; ++ (nullable NSURL *)phoneAuthURL; + (BOOL)isAuthenticated; -+ (void)authenticateWithToken:(NSString * _Nonnull)token ++ (NSString *)termsOfUseLink; ++ (NSString *)privacyPolicyLink; + ++ (void)authenticateWithToken:(NSString *)token type:(MWMSocialTokenType)type privacyAccepted:(BOOL)privacyAccepted termsAccepted:(BOOL)termsAccepted promoAccepted:(BOOL)promoAccepted source:(MWMAuthorizationSource)source - onComplete:(MWMAuthorizationCompleteBlock _Nonnull)onComplete; -+ (NSString * _Nonnull)termsOfUseLink; -+ (NSString * _Nonnull)privacyPolicyLink; + onComplete:(MWMBoolBlock)onComplete; @end + +NS_ASSUME_NONNULL_END diff --git a/iphone/CoreApi/CoreApi/User/MWMUser.mm b/iphone/CoreApi/CoreApi/User/MWMUser.mm new file mode 100644 index 0000000000..259ace6a74 --- /dev/null +++ b/iphone/CoreApi/CoreApi/User/MWMUser.mm @@ -0,0 +1,55 @@ +#import "MWMUser.h" + +#include + +@implementation MWMUser + ++ (nullable NSURL *)phoneAuthURL { + return [NSURL URLWithString:@(GetFramework().GetUser().GetPhoneAuthUrl("http://localhost").c_str())]; +} + ++ (BOOL)isAuthenticated { + return GetFramework().GetUser().IsAuthenticated(); +} + ++ (NSString *)termsOfUseLink { + return @(User::GetTermsOfUseLink().c_str()); +} + ++ (NSString *)privacyPolicyLink { + return @(User::GetPrivacyPolicyLink().c_str()); +} + ++ (void)authenticateWithToken:(NSString *)token + type:(MWMSocialTokenType)type + privacyAccepted:(BOOL)privacyAccepted + termsAccepted:(BOOL)termsAccepted + promoAccepted:(BOOL)promoAccepted + source:(MWMAuthorizationSource)source + onComplete:(MWMBoolBlock)onComplete { + auto &user = GetFramework().GetUser(); + User::SocialTokenType socialTokenType; + NSString *provider = nil; + switch (type) { + case MWMSocialTokenTypeGoogle: + socialTokenType = User::SocialTokenType::Google; + break; + case MWMSocialTokenTypeFacebook: + socialTokenType = User::SocialTokenType::Facebook; + break; + case MWMSocialTokenTypePhone: + socialTokenType = User::SocialTokenType::Phone; + break; + } + auto s = std::make_unique(); + s->m_postCallAction = User::Subscriber::Action::RemoveSubscriber; + s->m_onAuthenticate = [provider, source, onComplete](bool success) { + dispatch_async(dispatch_get_main_queue(), ^{ + onComplete(success); + }); + }; + user.AddSubscriber(std::move(s)); + user.Authenticate(token.UTF8String, socialTokenType, privacyAccepted, termsAccepted, promoAccepted); +} + +@end diff --git a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift index b6025b6738..1b634a2ef9 100644 --- a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift @@ -228,13 +228,13 @@ class PaidRouteViewController: MWMViewController { } @IBAction func onTerms(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.termsOfUseLink()) else { return } + guard let url = URL(string: User.termsOfUseLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } @IBAction func onPrivacy(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.privacyPolicyLink()) else { return } + guard let url = URL(string: User.privacyPolicyLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift index f2061d161a..40cd30efc5 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift @@ -123,13 +123,13 @@ class BaseSubscriptionViewController: MWMViewController { } @IBAction func onTerms(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.termsOfUseLink()) else { return } + guard let url = URL(string: User.termsOfUseLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } @IBAction func onPrivacy(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.privacyPolicyLink()) else { return } + guard let url = URL(string: User.privacyPolicyLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index 74dd883f3a..eac7335867 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -39,7 +39,7 @@ final class BMCDefaultViewModel: NSObject { } private func setPermissions() { - isAuthenticated = MWMAuthorizationViewModel.isAuthenticated() + isAuthenticated = User.isAuthenticated() if !isAuthenticated { Statistics.logEvent(kStatBookmarksSyncProposalShown, withParameters: [kStatHasAuthorization: 0]) permissions = [.signup] diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift index 74eba9c0b2..85ae0be45f 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift @@ -50,7 +50,7 @@ final class BookmarksSharingViewController: MWMTableViewController { @IBOutlet private weak var licenseAgreementTextView: UITextView! { didSet { let htmlString = String(coreFormat: L("ugc_routes_user_agreement"), - arguments: [MWMAuthorizationViewModel.termsOfUseLink()]) + arguments: [User.termsOfUseLink()]) let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular14(), NSAttributedString.Key.foregroundColor: UIColor.blackSecondaryText()] licenseAgreementTextView.attributedText = NSAttributedString.string(withHtml: htmlString, diff --git a/iphone/Maps/Bridging-Header.h b/iphone/Maps/Bridging-Header.h index 6195aed85e..268f4e902c 100644 --- a/iphone/Maps/Bridging-Header.h +++ b/iphone/Maps/Bridging-Header.h @@ -29,7 +29,6 @@ #import "MapViewController.h" #import "MWMActivityViewController.h" #import "MWMAlertViewController.h" -#import "MWMAuthorizationViewModel.h" #import "MWMAvailableAreaAffectDirection.h" #import "MWMBanner.h" #import "MWMBottomMenuViewController.h" diff --git a/iphone/Maps/Categories/UIViewController+Authorization.swift b/iphone/Maps/Categories/UIViewController+Authorization.swift index 67e2981345..0d51319b7e 100644 --- a/iphone/Maps/Categories/UIViewController+Authorization.swift +++ b/iphone/Maps/Categories/UIViewController+Authorization.swift @@ -1,6 +1,6 @@ extension UIViewController { @objc func signup(anchor: UIView, onComplete: @escaping (Bool) -> Void) { - if MWMAuthorizationViewModel.isAuthenticated() { + if User.isAuthenticated() { onComplete(true) } else { let authVC = AuthorizationViewController(popoverSourceView: anchor, diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index dd17338642..460d028c09 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -70,7 +70,6 @@ 3406FA191C6E0D8F00E9FAD2 /* MWMMapDownloadDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3406FA171C6E0D8F00E9FAD2 /* MWMMapDownloadDialog.xib */; }; 340708651F2905A500029ECC /* NavigationInfoArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340708631F2905A500029ECC /* NavigationInfoArea.swift */; }; 340708781F2B5D6C00029ECC /* DimBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340708761F2B5D6C00029ECC /* DimBackground.swift */; }; - 3408963F1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3408963D1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm */; }; 3409D50B1FC6D8D2000F9B3E /* FilterCheckCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3409D5091FC6D8D2000F9B3E /* FilterCheckCell.swift */; }; 340B33C61F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */; }; 340E1EEC1E2F614400CE49BF /* Authorization.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 340E1EE41E2F614400CE49BF /* Authorization.storyboard */; }; @@ -972,8 +971,6 @@ 340837121B7243CE00B5C185 /* MWMActivityViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMActivityViewController.mm; sourceTree = ""; }; 340837141B72451A00B5C185 /* MWMShareActivityItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMShareActivityItem.h; sourceTree = ""; }; 340837151B72451A00B5C185 /* MWMShareActivityItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMShareActivityItem.mm; sourceTree = ""; }; - 3408963C1F83CEDE00BC7117 /* MWMAuthorizationViewModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMAuthorizationViewModel.h; sourceTree = ""; }; - 3408963D1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMAuthorizationViewModel.mm; sourceTree = ""; }; 3409D5091FC6D8D2000F9B3E /* FilterCheckCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCheckCell.swift; sourceTree = ""; }; 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "MWMRouter+RouteManager.mm"; sourceTree = ""; }; 340DC82B1C4E72C700EAA2CC /* liboauthcpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liboauthcpp.a; path = "../../../omim-xcode-build/Debug/liboauthcpp.a"; sourceTree = ""; }; @@ -3277,8 +3274,6 @@ 34BBD6561F826F810070CA50 /* AuthorizationTransitioningManager.swift */, 34BBD64A1F826DB10070CA50 /* AuthorizationViewController.swift */, 34BBD6661F8273350070CA50 /* AuthorizationViewController.xib */, - 3408963C1F83CEDE00BC7117 /* MWMAuthorizationViewModel.h */, - 3408963D1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm */, 47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */, ); path = Authorization; @@ -5312,7 +5307,6 @@ 47F86D0120C93D8D00FEE291 /* TabViewController.swift in Sources */, 99536113235DB86C008B218F /* BookmarksSubscriptionDiscountLabel.swift in Sources */, 6741A9A51BF340DE002C974C /* MWMShareActivityItem.mm in Sources */, - 3408963F1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm in Sources */, F6E2FE1F1E097BA00083EBEC /* MWMOpeningHoursCommon.mm in Sources */, 3454D7B91E07F045004AF2AD /* CALayer+RuntimeAttributes.m in Sources */, 99E2B0232369904800FFABC5 /* WelcomeViewController.swift in Sources */, diff --git a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift index ab345b89b3..33c4c26237 100644 --- a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift +++ b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift @@ -169,13 +169,13 @@ import SafariServices } @IBAction func onTerms(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.termsOfUseLink()) else { return } + guard let url = URL(string: User.termsOfUseLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } @IBAction func onPrivacy(_ sender: UIButton) { - guard let url = URL(string: MWMAuthorizationViewModel.privacyPolicyLink()) else { return } + guard let url = URL(string: User.privacyPolicyLink()) else { return } let safari = SFSafariViewController(url: url) self.present(safari, animated: true, completion: nil) } diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift index f1d090732e..a9f402840d 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift @@ -3,9 +3,13 @@ import FBSDKLoginKit import GoogleSignIn import SafariServices +@objc enum AuthorizationError: Int { + case cancelled + case passportError +} + @objc(MWMAuthorizationViewController) final class AuthorizationViewController: MWMViewController { - typealias ViewModel = MWMAuthorizationViewModel private let transitioningManager: AuthorizationTransitioningManager @@ -152,7 +156,7 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var privacyPolicyTextView: UITextView! { didSet { - let htmlString = String(coreFormat: L("sign_agree_pp_gdpr"), arguments: [ViewModel.privacyPolicyLink()]) + let htmlString = String(coreFormat: L("sign_agree_pp_gdpr"), arguments: [User.privacyPolicyLink()]) let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] privacyPolicyTextView.attributedText = NSAttributedString.string(withHtml: htmlString, @@ -163,7 +167,7 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var termsOfUseTextView: UITextView! { didSet { - let htmlString = String(coreFormat: L("sign_agree_tof_gdpr"), arguments: [ViewModel.termsOfUseLink()]) + let htmlString = String(coreFormat: L("sign_agree_tof_gdpr"), arguments: [User.termsOfUseLink()]) let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: UIFont.regular16(), NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText()] termsOfUseTextView.attributedText = NSAttributedString.string(withHtml: htmlString, @@ -183,17 +187,17 @@ final class AuthorizationViewController: MWMViewController { @IBOutlet private weak var topToContentConstraint: NSLayoutConstraint! - typealias SuccessHandler = (MWMSocialTokenType) -> Void - typealias ErrorHandler = (MWMAuthorizationError) -> Void + typealias SuccessHandler = (SocialTokenType) -> Void + typealias ErrorHandler = (AuthorizationError) -> Void typealias CompletionHandler = (AuthorizationViewController) -> Void - private let sourceComponent: MWMAuthorizationSource + private let sourceComponent: AuthorizationSource private let successHandler: SuccessHandler? private let errorHandler: ErrorHandler? private let completionHandler: CompletionHandler? @objc - init(barButtonItem: UIBarButtonItem?, sourceComponent: MWMAuthorizationSource, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { + init(barButtonItem: UIBarButtonItem?, sourceComponent: AuthorizationSource, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { self.sourceComponent = sourceComponent self.successHandler = successHandler self.errorHandler = errorHandler @@ -205,7 +209,7 @@ final class AuthorizationViewController: MWMViewController { } @objc - init(popoverSourceView: UIView? = nil, sourceComponent: MWMAuthorizationSource, permittedArrowDirections: UIPopoverArrowDirection = .unknown, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { + init(popoverSourceView: UIView? = nil, sourceComponent: AuthorizationSource, permittedArrowDirections: UIPopoverArrowDirection = .unknown, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { self.sourceComponent = sourceComponent self.successHandler = successHandler self.errorHandler = errorHandler @@ -249,15 +253,17 @@ final class AuthorizationViewController: MWMViewController { completionHandler?(self) } - private func getProviderStatStr(type: MWMSocialTokenType) -> String { + private func getProviderStatStr(type: SocialTokenType) -> String { switch type { case .facebook: return kStatFacebook case .google: return kStatGoogle case .phone: return kStatPhone + @unknown default: + fatalError() } } - private func process(error: Error, type: MWMSocialTokenType) { + private func process(error: Error, type: SocialTokenType) { Statistics.logEvent(kStatUGCReviewAuthError, withParameters: [ kStatProvider: getProviderStatStr(type: type), kStatError: error.localizedDescription, @@ -266,22 +272,54 @@ final class AuthorizationViewController: MWMViewController { Crashlytics.sharedInstance().recordError(error) } - private func process(token: String, type: MWMSocialTokenType) { - Statistics.logEvent(kStatUGCReviewAuthExternalRequestSuccess, withParameters: [kStatProvider: getProviderStatStr(type: type)]) - ViewModel.authenticate(withToken: token, - type: type, - privacyAccepted: privacyPolicyCheck.isChecked, - termsAccepted: termsOfUseCheck.isChecked, - promoAccepted: latestNewsCheck.isChecked, - source: sourceComponent) { success in - if success { - self.successHandler?(type) - } else { - self.errorHandler?(.passportError) - } + private func process(token: String, type: SocialTokenType) { + Statistics.logEvent(kStatUGCReviewAuthExternalRequestSuccess, + withParameters: [kStatProvider: getProviderStatStr(type: type)]) + User.authenticate(withToken: token, + type: type, + privacyAccepted: privacyPolicyCheck.isChecked, + termsAccepted: termsOfUseCheck.isChecked, + promoAccepted: latestNewsCheck.isChecked, + source: sourceComponent) { success in + self.logStats(type: type, success: success) + if success { + self.successHandler?(type) + } else { + self.errorHandler?(.passportError) + } } onClose() } + + private func logStats(type: SocialTokenType, success: Bool) { + let provider: String + switch type { + case .google: + provider = kStatGoogle + case .facebook: + provider = kStatFacebook + case .phone: + provider = kStatPhone + @unknown default: + fatalError() + } + + let event: String? + switch self.sourceComponent { + case .UGC: + event = success ? kStatUGCReviewAuthRequestSuccess : kStatUGCReviewAuthError + case .bookmarks: + event = success ? kStatBookmarksAuthRequestSuccess : kStatBookmarksAuthRequestError + @unknown default: + fatalError() + } + + if success { + Statistics.logEvent(event, withParameters: [kStatProvider : provider]) + } else { + Statistics.logEvent(event, withParameters: [kStatProvider : provider, kStatError : ""]) + } + } } extension AuthorizationViewController: GIDSignInUIDelegate { diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.xib b/iphone/Maps/UI/Authorization/AuthorizationViewController.xib index 9e95c339e0..7a1280ded2 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.xib +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -42,7 +40,7 @@ - + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - + + + + + + diff --git a/iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.mm b/iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.mm deleted file mode 100644 index 541035321c..0000000000 --- a/iphone/Maps/UI/Authorization/MWMAuthorizationViewModel.mm +++ /dev/null @@ -1,78 +0,0 @@ -#import "MWMAuthorizationViewModel.h" -#import "Statistics.h" - -#include - -@implementation MWMAuthorizationViewModel - -+ (NSURL * _Nullable)phoneAuthURL -{ - return [NSURL URLWithString:@(GetFramework().GetUser().GetPhoneAuthUrl("http://localhost").c_str())]; -} - -+ (BOOL)isAuthenticated { return GetFramework().GetUser().IsAuthenticated(); } - -+ (void)authenticateWithToken:(NSString * _Nonnull)token - type:(MWMSocialTokenType)type - privacyAccepted:(BOOL)privacyAccepted - termsAccepted:(BOOL)termsAccepted - promoAccepted:(BOOL)promoAccepted - source:(MWMAuthorizationSource)source - onComplete:(MWMAuthorizationCompleteBlock)onComplete -{ - auto & user = GetFramework().GetUser(); - User::SocialTokenType socialTokenType; - NSString * provider = nil; - switch (type) - { - case MWMSocialTokenTypeGoogle: - provider = kStatGoogle; - socialTokenType = User::SocialTokenType::Google; - break; - case MWMSocialTokenTypeFacebook: - provider = kStatFacebook; - socialTokenType = User::SocialTokenType::Facebook; - break; - case MWMSocialTokenTypePhone: - provider = kStatPhone; - socialTokenType = User::SocialTokenType::Phone; - break; - } - auto s = std::make_unique(); - s->m_postCallAction = User::Subscriber::Action::RemoveSubscriber; - s->m_onAuthenticate = [provider, source, onComplete](bool success) { - NSString * event = nil; - switch (source) - { - case MWMAuthorizationSourceUGC: - event = success ? kStatUGCReviewAuthRequestSuccess : kStatUGCReviewAuthError; - break; - case MWMAuthorizationSourceBookmarks: - event = success ? kStatBookmarksAuthRequestSuccess : kStatBookmarksAuthRequestError; - break; - } - - if (success) - [Statistics logEvent:event withParameters:@{kStatProvider: provider}]; - else - [Statistics logEvent:event withParameters:@{kStatProvider: kStatMapsme, kStatError: @""}]; - dispatch_async(dispatch_get_main_queue(), ^{ - onComplete(success); - }); - }; - user.AddSubscriber(std::move(s)); - user.Authenticate(token.UTF8String, socialTokenType, privacyAccepted, - termsAccepted, promoAccepted); -} - -+ (NSString * _Nonnull)termsOfUseLink -{ - return @(User::GetTermsOfUseLink().c_str()); -} - -+ (NSString * _Nonnull)privacyPolicyLink -{ - return @(User::GetPrivacyPolicyLink().c_str()); -} - -@end diff --git a/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift b/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift index 3605e8b103..0bdb4d48eb 100644 --- a/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift @@ -2,7 +2,7 @@ class PhoneNumberAuthorizationViewController: WebViewController { var failure: MWMVoidBlock? init(success: @escaping MWMStringBlock, failure: @escaping MWMVoidBlock) { - super.init(authURL: MWMAuthorizationViewModel.phoneAuthURL()!, onSuccessAuth: success, onFailure: failure)! + super.init(authURL: User.phoneAuthURL()!, onSuccessAuth: success, onFailure: failure)! self.failure = failure } diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index d413fcd93b..ae71e04ed5 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -702,7 +702,7 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page: } [Statistics logEvent:kStatUGCReviewStart withParameters:@{ - kStatIsAuthenticated: @([MWMAuthorizationViewModel isAuthenticated]), + kStatIsAuthenticated: @([MWMUser isAuthenticated]), kStatIsOnline: @(GetPlatform().ConnectionStatus() != Platform::EConnectionType::CONNECTION_NONE), kStatMode: kStatAdd, diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift index b3b0ab0b42..90b3a7f766 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift @@ -84,8 +84,8 @@ final class UGCAddReviewController: MWMTableViewController { let onError = { Toast.toast(withText: L("ugc_thanks_message_not_auth")).show() } let onComplete = { () -> Void in nc.popToRootViewController(animated: true) } - if MWMAuthorizationViewModel.isAuthenticated() || !FrameworkHelper.isNetworkConnected() { - if MWMAuthorizationViewModel.isAuthenticated() { + if User.isAuthenticated() || !FrameworkHelper.isNetworkConnected() { + if User.isAuthenticated() { onSuccess() } else { onError() diff --git a/iphone/Maps/UI/Welcome/TermsOfUse/TermsOfUsePresenter.swift b/iphone/Maps/UI/Welcome/TermsOfUse/TermsOfUsePresenter.swift index 6001ea97fa..210877db50 100644 --- a/iphone/Maps/UI/Welcome/TermsOfUse/TermsOfUsePresenter.swift +++ b/iphone/Maps/UI/Welcome/TermsOfUse/TermsOfUsePresenter.swift @@ -7,8 +7,8 @@ class TermsOfUsePresenter { private weak var view: ITermsOfUseView? private let router: WelcomeRouterProtocol - let privacyPolicyLink = MWMAuthorizationViewModel.privacyPolicyLink() - let termsOfUseLink = MWMAuthorizationViewModel.termsOfUseLink() + let privacyPolicyLink = User.privacyPolicyLink() + let termsOfUseLink = User.termsOfUseLink() init(view: ITermsOfUseView, router: WelcomeRouterProtocol) { self.view = view