Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ target 'WooCommerce' do
pod 'Gridicons', '~> 1.0'

# To allow pod to pick up beta versions use -beta. E.g., 1.1.7-beta.1
pod 'WordPressAuthenticator', '~> 1.31.0-beta.2'
pod 'WordPressAuthenticator', '~> 1.31.0-beta.3'
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => ''
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :branch => 'develop'
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :branch => ''
# pod 'WordPressAuthenticator', :path => '../WordPressAuthenticator-iOS'

pod 'WordPressShared', '~> 1.12'
Expand Down
12 changes: 6 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PODS:
- WordPress-Aztec-iOS (1.11.0)
- WordPress-Editor-iOS (1.11.0):
- WordPress-Aztec-iOS (= 1.11.0)
- WordPressAuthenticator (1.31.0-beta.2):
- WordPressAuthenticator (1.31.0-beta.3):
- 1PasswordExtension (= 1.8.6)
- Alamofire (= 4.8)
- CocoaLumberjack (~> 3.5)
Expand All @@ -66,7 +66,7 @@ PODS:
- WordPressKit (~> 4.18-beta)
- WordPressShared (~> 1.12-beta)
- WordPressUI (~> 1.7.0)
- WordPressKit (4.23.0-beta.1):
- WordPressKit (4.23.0-beta.4):
- Alamofire (~> 4.8.0)
- CocoaLumberjack (~> 3.4)
- NSObject-SafeExpectations (= 0.0.4)
Expand Down Expand Up @@ -107,7 +107,7 @@ DEPENDENCIES:
- Kingfisher (~> 5.11.0)
- Sourcery (~> 0.18)
- WordPress-Editor-iOS (~> 1.11.0)
- WordPressAuthenticator (~> 1.31.0-beta.2)
- WordPressAuthenticator (~> 1.31.0-beta.3)
- WordPressShared (~> 1.12)
- WordPressUI (~> 1.7.2)
- Wormholy (~> 1.6.2)
Expand Down Expand Up @@ -182,8 +182,8 @@ SPEC CHECKSUMS:
UIDeviceIdentifier: f4bf3b343581a1beacdbf5fb1a8825bd5f05a4a4
WordPress-Aztec-iOS: 050b34d4c3adfb7c60363849049b13d60683b348
WordPress-Editor-iOS: 304098424f1051cb271546c99f906aac296b1b81
WordPressAuthenticator: 6144728478567e3ecb9514ac0ac434d203e7f26b
WordPressKit: d67438d29c84960585ecef9a595e9f214b42cc87
WordPressAuthenticator: b43cd7f1ec8eb0bd2efd5b7b93d16d72be402046
WordPressKit: 3cba388ffed57891c3821e1efc08a2b71382b214
WordPressShared: 532ad68f954d37ea901e8c7e3ca62913c43ff787
WordPressUI: 07ad23f17631bdce0171383e533eb7c4c29280aa
Wormholy: bfc1c8679eefd0edd92638758e21c3961b1b3b50
Expand All @@ -198,6 +198,6 @@ SPEC CHECKSUMS:
ZendeskSupportProvidersSDK: 51c9d4a826f7bd87e3109e5c801c602a6b62c762
ZendeskSupportSDK: dcb2596ad05a63d662e8c7924357babbf327b421

PODFILE CHECKSUM: 983b843c2b4973c3d8e6ea4353ae0f2ccdf945f1
PODFILE CHECKSUM: 25565253d6035bcea3995dcf6c1d42ac1e060c27

COCOAPODS: 1.9.1
34 changes: 27 additions & 7 deletions WooCommerce/Classes/Authentication/AuthenticationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,15 @@ extension AuthenticationManager: WordPressAuthenticatorDelegate {
func createdWordPressComAccount(username: String, authToken: String) { }

func shouldHandleError(_ error: Error) -> Bool {
guard AuthenticationError.make(with: error) == .notWPSite else {
return false
}

return true
return isSupportedError(error)
}

func handleError(_ error: Error, onCompletion: @escaping (UIViewController) -> Void) {
let viewModel = NotWPErrorViewModel()
let noWPErrorUI = ULErrorViewController(viewModel: viewModel)
guard let errorViewModel = viewModel(error) else {
return
}

let noWPErrorUI = ULErrorViewController(viewModel: errorViewModel)

onCompletion(noWPErrorUI)
}
Expand Down Expand Up @@ -341,18 +340,39 @@ private extension AuthenticationManager {

/// Maps error codes emitted by WPAuthenticator to a domain error object
enum AuthenticationError: Int, Error {
case emailDoesNotMatchWPAccount = 7
case notWPSite = 406
case unknown

static func make(with error: Error) -> AuthenticationError {
let error = error as NSError

switch error.code {
case emailDoesNotMatchWPAccount.rawValue:
return .emailDoesNotMatchWPAccount
case notWPSite.rawValue:
return .notWPSite
default:
return .unknown
}
}
}

func isSupportedError(_ error: Error) -> Bool {
let wooAuthError = AuthenticationError.make(with: error)
return wooAuthError != .unknown
}

func viewModel(_ error: Error) -> ULErrorViewModel? {
let wooAuthError = AuthenticationError.make(with: error)

switch wooAuthError {
case .emailDoesNotMatchWPAccount:
return NotWPAccountViewModel()
case .notWPSite:
return NotWPErrorViewModel()
default:
return nil
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import UIKit
import SafariServices
import WordPressAuthenticator
import WordPressUI


/// Configuration and actions for an ULErrorViewController, modeling
/// an error when user attempts to log in with an invalid WordPressAccount
struct NotWPAccountViewModel: ULErrorViewModel {
// MARK: - Data and configuration
let image: UIImage = .loginNoWordPressError

let text: NSAttributedString = .init(string: Localization.errorMessage)

let isAuxiliaryButtonHidden = false

let auxiliaryButtonTitle = Localization.needHelpFindingEmail

let primaryButtonTitle = Localization.primaryButtonTitle

let secondaryButtonTitle = Localization.secondaryButtonTitle

// MARK: - Actions
func didTapPrimaryButton(in viewController: UIViewController?) {
let popCommand = NavigateToEnterSite()
popCommand.execute(from: viewController)
}

func didTapSecondaryButton(in viewController: UIViewController?) {
let refreshCommand = NavigateToRoot()
refreshCommand.execute(from: viewController)
}

func didTapAuxiliaryButton(in viewController: UIViewController?) {
let fancyAlert = FancyAlertViewController.makeNeedHelpFindingEmailAlertController()
fancyAlert.modalPresentationStyle = .custom
fancyAlert.transitioningDelegate = AppDelegate.shared.tabBarController
viewController?.present(fancyAlert, animated: true)
}
}


// MARK: - Private data structures
private extension NotWPAccountViewModel {
enum Localization {
static let errorMessage = NSLocalizedString("It looks like this email isn't associated with a WordPress.com account.",
comment: "Message explaining that an email is not associated with a WordPress.com account. "
+ "Presented when logging in with an email address that is not a WordPress.com account")

static let needHelpFindingEmail = NSLocalizedString("Need help finding the connected email?",
comment: "Button linking to webview that explains what Jetpack is"
+ "Presented when logging in with a site address that does not have a valid Jetpack installation")

static let primaryButtonTitle = NSLocalizedString("Enter Your Store Address",
comment: "Action button linking to instructions for enter another store."
+ "Presented when logging in with an email address that is not a WordPress.com account")

static let secondaryButtonTitle = NSLocalizedString("Log In With Another Account",
comment: "Action button that will restart the login flow."
+ "Presented when logging in with an email address that does not match a WordPress.com account")

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private extension ULErrorViewController {
}

extraInfoButton.applyLinkButtonStyle()
extraInfoButton.contentEdgeInsets = Constants.extraInfoCustomInsets
extraInfoButton.setTitle(viewModel.auxiliaryButtonTitle, for: .normal)
extraInfoButton.on(.touchUpInside) { [weak self] _ in
self?.didTapAuxiliaryButton()
Expand Down Expand Up @@ -97,6 +98,13 @@ private extension ULErrorViewController {
}


// MARK: - Constants
private extension ULErrorViewController {
enum Constants {
static let extraInfoCustomInsets = UIEdgeInsets(top: 12, left: 10, bottom: 12, right: 10)
}
}

// MARK: - Tests
extension ULErrorViewController {
func getImageView() -> UIImageView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="32" translatesAutoresizingMaskIntoConstraints="NO" id="jIt-xb-rrN">
<rect key="frame" x="40" y="257" width="334" height="352.5"/>
<rect key="frame" x="34" y="268" width="346" height="330.5"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="woo-no-jetpack-error" translatesAutoresizingMaskIntoConstraints="NO" id="Osv-Wo-lxW">
<rect key="frame" x="26.5" y="0.0" width="281" height="150"/>
<rect key="frame" x="32.5" y="0.0" width="281" height="150"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="a2d-le-aKc">
<rect key="frame" x="0.0" y="182" width="334" height="108.5"/>
<rect key="frame" x="0.0" y="182" width="346" height="86.5"/>
<string key="text">Qui eum est quo et recusandae ut. Hic cupiditate nobis et pariatur quidem dolorum. Doloribus est tempora ipsam eius. Quos ab et aspernatur velit corporis aut rem.</string>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GOR-hg-dbC" userLabel="Action Button">
<rect key="frame" x="53" y="322.5" width="228" height="30"/>
<rect key="frame" x="59" y="300.5" width="228" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="228" id="Dh0-gH-21U"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="228" id="Dh0-gH-21U"/>
</constraints>
<state key="normal" title="Action Button"/>
</button>
Expand All @@ -94,9 +94,9 @@
<constraints>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="10Z-y1-ZQ6" secondAttribute="trailing" id="3Fe-tr-bmb"/>
<constraint firstItem="jIt-xb-rrN" firstAttribute="top" relation="greaterThanOrEqual" secondItem="fnl-2z-Ty3" secondAttribute="top" constant="8" id="4vu-ll-3S2"/>
<constraint firstAttribute="trailing" secondItem="jIt-xb-rrN" secondAttribute="trailing" constant="40" id="Z7E-hC-lbB"/>
<constraint firstAttribute="trailing" secondItem="jIt-xb-rrN" secondAttribute="trailing" constant="34" id="Z7E-hC-lbB"/>
<constraint firstItem="jIt-xb-rrN" firstAttribute="centerY" secondItem="fnl-2z-Ty3" secondAttribute="centerY" constant="-20" id="ZZg-jd-e4d"/>
<constraint firstItem="jIt-xb-rrN" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="40" id="jMe-jj-6Bt"/>
<constraint firstItem="jIt-xb-rrN" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="34" id="jMe-jj-6Bt"/>
<constraint firstItem="10Z-y1-ZQ6" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="r9Z-y5-j3W"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="10Z-y1-ZQ6" secondAttribute="bottom" id="rPP-rT-zVR"/>
</constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public extension FancyAlertViewController {
let dismissButton = makeDismissButtonConfig()
let moreInfoButton = makeMoreInfoButtonConfig()
let config = FancyAlertViewController.Config(titleText: Localization.whatIsJetpack,
bodyText: Localization.longDescription,
bodyText: Localization.whatIsJetpackLongDescription,
headerImage: .whatIsJetpackImage,
dividerPosition: .top,
defaultButton: dismissButton,
Expand All @@ -17,6 +17,23 @@ public extension FancyAlertViewController {
let controller = FancyAlertViewController.controllerWithConfiguration(configuration: config)
return controller
}

static func makeNeedHelpFindingEmailAlertController() -> FancyAlertViewController {
let dismissButton = makeDismissButtonConfig()
let moreHelpButton = makeNeedMoreHelpButton()
let config = FancyAlertViewController.Config(titleText: Localization.whatEmailDoIUse,
bodyText: Localization.whatEmailDoIUseLongDescription,
headerImage: nil,
dividerPosition: .top,
defaultButton: dismissButton,
cancelButton: nil,
moreInfoButton: moreHelpButton,
dismissAction: {})

let controller = FancyAlertViewController.controllerWithConfiguration(configuration: config)
return controller

}
}


Expand All @@ -27,7 +44,7 @@ private extension FancyAlertViewController {
comment: "Title of alert informing users of what Jetpack is. Presented when users attempt to log in without Jetpack installed or connected"
)

static let longDescription = NSLocalizedString(
static let whatIsJetpackLongDescription = NSLocalizedString(
"Jetpack is a free WordPress plugin that connects your store with tools needed to give you the best mobile experience, "
+ "including push notifications and stats",
comment: "Long description of what Jetpack is. Presented when users attempt to log in without Jetpack installed or connected"
Expand All @@ -42,6 +59,23 @@ private extension FancyAlertViewController {
"Continue",
comment: "Title of dismiss button presented when users attempt to log in without Jetpack installed or connected"
)

static let whatEmailDoIUse = NSLocalizedString(
"What email do I use to sign in?",
comment: "Title of alert informing users of what email they can use to sign in."
+ "Presented when users attempt to log in with an email that does not match a WP.com account"
)

static let whatEmailDoIUseLongDescription = NSLocalizedString(
"In your site admin you can find the email you used to connect to WordPress.com from the Jetpack Dashboard under Connections > Account Connection",
comment: "Long descriptions of alert informing users of what email they can use to sign in."
+ "Presented when users attempt to log in with an email that does not match a WP.com account"
)

static let needMoreHelp = NSLocalizedString(
"Need more help?",
comment: "Title of button to learn more presented when users attempt to log in with an email address that does not match a WP.com account"
)
}

enum Strings {
Expand Down Expand Up @@ -70,4 +104,22 @@ private extension FancyAlertViewController {
controller.present(safariViewController, animated: true)
}
}

static func makeNeedMoreHelpButton() -> FancyAlertViewController.Config.ButtonConfig {
return FancyAlertViewController.Config.ButtonConfig(Localization.needMoreHelp) { controller, _ in
let identifier = HelpAndSupportViewController.classNameWithoutNamespaces
guard let supportViewController = UIStoryboard
.dashboard
.instantiateViewController(withIdentifier: identifier) as? HelpAndSupportViewController else {
return
}

supportViewController.displaysDismissAction = true

let navController = UINavigationController(rootViewController: supportViewController)
navController.modalPresentationStyle = .formSheet

controller.present(navController, animated: true, completion: nil)
}
}
}
Loading