update auth api call, remove implicit third-party auth, UI polishing

This commit is contained in:
Aleksey Belousov 2018-05-15 19:28:22 +03:00 committed by Aleksey Belousov
parent 1a21e7844e
commit 067b198ddc
9 changed files with 42 additions and 58 deletions

View file

@ -106,8 +106,8 @@ final class BMCViewController: MWMViewController {
}
private func signup(anchor: UIView, onComplete: @escaping (Bool) -> Void) {
if MWMAuthorizationViewModel.hasSocialToken() {
MWMAuthorizationViewModel.checkAuthentication(with: .bookmarks, onComplete: onComplete)
if MWMAuthorizationViewModel.isAuthenticated() {
onComplete(true)
} else {
let authVC = AuthorizationViewController(popoverSourceView: anchor,
sourceComponent: .bookmarks,

View file

@ -80,8 +80,9 @@ class Checkmark: UIControl {
var width: CGFloat = imageView.width;
var height: CGFloat = imageView.height;
switch effectiveContentHorizontalAlignment {
case .right:
switch contentHorizontalAlignment {
case .right: fallthrough
case .trailing:
left = bounds.width - imageView.width
case .center:
left = floor(bounds.width - width) / 2

View file

@ -0,0 +1,15 @@
//
// LinkTextView.swift
// MAPS.ME
//
// Created by Aleksey Belousov on 15/05/2018.
// Copyright © 2018 MapsWithMe. All rights reserved.
//
import UIKit
class LinkTextView : UITextView {
override var canBecomeFirstResponder: Bool {
return false;
}
}

View file

@ -348,6 +348,7 @@
4767CD9F20AAD48A00BD8166 /* Checkmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CD9E20AAD48A00BD8166 /* Checkmark.swift */; };
4767CDA420AAF66B00BD8166 /* NSAttributedString+HTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA320AAF66B00BD8166 /* NSAttributedString+HTML.swift */; };
4767CDA620AB1F6200BD8166 /* LeftAlignedIconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA520AB1F6200BD8166 /* LeftAlignedIconButton.swift */; };
4767CDA820AB401000BD8166 /* LinkTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4767CDA720AB401000BD8166 /* LinkTextView.swift */; };
4A300ED51C6DCFD400140018 /* countries-strings in Resources */ = {isa = PBXBuildFile; fileRef = 4A300ED31C6DCFD400140018 /* countries-strings */; };
56C74C391C74A3BC00B71B9F /* MWMInputEmailValidator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34ABA62F1C2D58F300FE1BEC /* MWMInputEmailValidator.mm */; };
56EE14D11FE804550036F20C /* libtransit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 56EE14D21FE804550036F20C /* libtransit.a */; };
@ -1277,6 +1278,7 @@
4767CD9E20AAD48A00BD8166 /* Checkmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkmark.swift; sourceTree = "<group>"; };
4767CDA320AAF66B00BD8166 /* NSAttributedString+HTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+HTML.swift"; sourceTree = "<group>"; };
4767CDA520AB1F6200BD8166 /* LeftAlignedIconButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftAlignedIconButton.swift; sourceTree = "<group>"; };
4767CDA720AB401000BD8166 /* LinkTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkTextView.swift; sourceTree = "<group>"; };
4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_dark.bin; path = ../../data/drules_proto_dark.bin; sourceTree = "<group>"; };
4A23D1561B8B4DD700D4EB6F /* drules_proto_clear.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_clear.bin; path = ../../data/drules_proto_clear.bin; sourceTree = "<group>"; };
4A23D1571B8B4DD700D4EB6F /* resources-6plus_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-6plus_clear"; path = "../../data/resources-6plus_clear"; sourceTree = "<group>"; };
@ -2558,6 +2560,7 @@
348A8DF01F66775A00D83026 /* RatingView */,
4767CD9E20AAD48A00BD8166 /* Checkmark.swift */,
4767CDA520AB1F6200BD8166 /* LeftAlignedIconButton.swift */,
4767CDA720AB401000BD8166 /* LinkTextView.swift */,
);
path = Components;
sourceTree = "<group>";
@ -4664,6 +4667,7 @@
F6E2FEC41E097BA00083EBEC /* MWMSearchFilterPresentationController.mm in Sources */,
34AB66621FC5AA330078E451 /* TransportTransitSeparator.swift in Sources */,
340416541E7C09C200E2B6D6 /* PhotoScalingView.swift in Sources */,
4767CDA820AB401000BD8166 /* LinkTextView.swift in Sources */,
34763EE71F2F392300F4D2D3 /* MWMTextToSpeech.mm in Sources */,
34ABA6251C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */,
F6E2FD861E097BA00083EBEC /* MWMBaseMapDownloaderViewController.mm in Sources */,

View file

@ -272,7 +272,12 @@ final class AuthorizationViewController: MWMViewController {
private func process(token: String, type: MWMSocialTokenType) {
Statistics.logEvent(kStatUGCReviewAuthExternalRequestSuccess, withParameters: [kStatProvider: getProviderStatStr(type: type)])
ViewModel.authenticate(withToken: token, type: type, source: sourceComponent) { success in
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 {

View file

@ -82,7 +82,7 @@
<action selector="onCheck:" destination="-1" eventType="valueChanged" id="GHm-Xj-Fic"/>
</connections>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to Privacy Policy" translatesAutoresizingMaskIntoConstraints="NO" id="LhW-gs-XN9">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to Privacy Policy" translatesAutoresizingMaskIntoConstraints="NO" id="LhW-gs-XN9" customClass="LinkTextView" customModule="maps_me" customModuleProvider="target">
<rect key="frame" x="40" y="10" width="182.5" height="35.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="16"/>
@ -127,7 +127,7 @@
<action selector="onCheck:" destination="-1" eventType="valueChanged" id="3jl-dT-yZS"/>
</connections>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to Terms of Use" translatesAutoresizingMaskIntoConstraints="NO" id="PBR-9l-2Gh">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to Terms of Use" translatesAutoresizingMaskIntoConstraints="NO" id="PBR-9l-2Gh" customClass="LinkTextView" customModule="maps_me" customModuleProvider="target">
<rect key="frame" x="40" y="10" width="178.5" height="35.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="16"/>
@ -166,7 +166,7 @@
<userDefinedRuntimeAttribute type="image" keyPath="onImage" value="radioBtnOn"/>
</userDefinedRuntimeAttributes>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to recieve latest news about our products" translatesAutoresizingMaskIntoConstraints="NO" id="p04-D7-97V">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="I agree to recieve latest news about our products" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p04-D7-97V">
<rect key="frame" x="40" y="10" width="263" height="35.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="16"/>

View file

@ -18,13 +18,13 @@ typedef void (^MWMAuthorizationCompleteBlock)(BOOL);
@interface MWMAuthorizationViewModel : NSObject
+ (NSURL * _Nullable)phoneAuthURL;
+ (void)checkAuthenticationWithSource:(MWMAuthorizationSource)source
onComplete:(MWMAuthorizationCompleteBlock _Nonnull)onComplete;
+ (BOOL)hasSocialToken;
+ (NSURL * _Nonnull)phoneAuthURL;
+ (BOOL)isAuthenticated;
+ (void)authenticateWithToken:(NSString * _Nonnull)token
type:(MWMSocialTokenType)type
privacyAccepted:(BOOL)privacyAccepted
termsAccepted:(BOOL)termsAccepted
promoAccepted:(BOOL)promoAccepted
source:(MWMAuthorizationSource)source
onComplete:(MWMAuthorizationCompleteBlock _Nonnull)onComplete;

View file

@ -14,47 +14,13 @@
return [NSURL URLWithString:@(GetFramework().GetUser().GetPhoneAuthUrl("http://localhost").c_str())];
}
+ (void)checkAuthenticationWithSource:(MWMAuthorizationSource)source
onComplete:(MWMAuthorizationCompleteBlock)onComplete
{
if ([self isAuthenticated])
{
onComplete(YES);
return;
}
auto googleToken = [GIDSignIn sharedInstance].currentUser.authentication.idToken;
if (googleToken)
{
[self authenticateWithToken:googleToken
type:MWMSocialTokenTypeGoogle
source:source
onComplete:onComplete];
return;
}
auto fbToken = [FBSDKAccessToken currentAccessToken].tokenString;
if (fbToken)
{
[self authenticateWithToken:fbToken
type:MWMSocialTokenTypeFacebook
source:source
onComplete:onComplete];
return;
}
onComplete(NO);
}
+ (BOOL)hasSocialToken
{
return [GIDSignIn sharedInstance].currentUser.authentication.idToken != nil ||
[FBSDKAccessToken currentAccessToken].tokenString != nil;
}
+ (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
{
@ -99,9 +65,8 @@
});
};
user.AddSubscriber(std::move(s));
//TODO: support privacy policy, terms of use and promo offers.
user.Authenticate(token.UTF8String, socialTokenType, false /* privacyAccepted */,
false /* termsAccepted */, false /* promoAccepted */);
user.Authenticate(token.UTF8String, socialTokenType, privacyAccepted,
termsAccepted, promoAccepted);
}
@end

View file

@ -64,12 +64,6 @@ final class UGCAddReviewController: MWMTableViewController {
guard let nc = navigationController else { return }
if MWMAuthorizationViewModel.isAuthenticated() || MWMPlatform.networkConnectionType() == .none {
nc.popViewController(animated: true)
return
}
if MWMAuthorizationViewModel.hasSocialToken() {
MWMAuthorizationViewModel.checkAuthentication(with: .UGC, onComplete: { _ in})
nc.popViewController(animated: true)
} else {
Statistics.logEvent(kStatUGCReviewAuthShown, withParameters: [kStatFrom: kStatAfterSave])
let authVC = AuthorizationViewController(barButtonItem: navigationItem.rightBarButtonItem!,