Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 06fa1f6

Browse files
authored
Merge pull request #652 from wordpress-mobile/wcios/login-errors
Pass a custom error for invalid WP.com email errors
2 parents a07b1de + 8591d33 commit 06fa1f6

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressAuthenticator'
5-
s.version = '2.1.0-beta.3'
5+
s.version = '2.1.0-beta.4'
66

77
s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
88
s.description = <<-DESC

WordPressAuthenticator/Navigation/NavigateToEnterAccount.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private extension NavigateToEnterAccount {
1515
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
1616
return
1717
}
18+
vc.source = .wpCom
1819

1920
navigationController?.pushViewController(vc, animated: true)
2021
}

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class LoginPrologueViewController: LoginViewController {
397397
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
398398
return
399399
}
400+
vc.source = .wpCom
400401

401402
navigationController?.pushViewController(vc, animated: true)
402403
}
@@ -436,15 +437,6 @@ class LoginPrologueViewController: LoginViewController {
436437
navigationController?.pushViewController(toVC, animated: true)
437438
}
438439

439-
private func presentGetStartedView() {
440-
guard let toVC = GetStartedViewController.instantiate(from: .getStarted) else {
441-
DDLogError("Failed to navigate to GetStartedViewController")
442-
return
443-
}
444-
445-
navigationController?.pushViewController(toVC, animated: true)
446-
}
447-
448440
// Shows the VC that handles both Google login & signup.
449441
private func presentUnifiedGoogleView() {
450442
guard let toVC = GoogleAuthViewController.instantiate(from: .googleAuth) else {

WordPressAuthenticator/Unified Auth/View Related/Get Started/GetStartedViewController.swift

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@ import UIKit
22
import SafariServices
33
import WordPressKit
44

5+
/// The source for the sign in flow for external tracking.
6+
public enum SignInSource {
7+
/// Initiated from the WP.com login CTA.
8+
case wpCom
9+
/// Initiated from the WP.com login flow that starts with site address.
10+
case wpComSiteAddress
11+
}
12+
13+
/// The error during the sign in flow.
14+
public enum SignInError: Error {
15+
case invalidWPComEmail(source: SignInSource)
16+
17+
init?(error: Error, source: SignInSource?) {
18+
let error = error as NSError
19+
20+
switch error.code {
21+
case WordPressComRestApiError.unknown.rawValue:
22+
let restAPIErrorCode = error.userInfo[WordPressComRestApi.ErrorKeyErrorCode] as? String
23+
if let source = source, restAPIErrorCode == "unknown_user" {
24+
self = .invalidWPComEmail(source: source)
25+
} else {
26+
return nil
27+
}
28+
default:
29+
return nil
30+
}
31+
}
32+
}
33+
534
class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
635

736
private enum ScreenMode {
@@ -36,6 +65,8 @@ class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
3665
// This is public so it can be set from StoredCredentialsAuthenticator.
3766
var errorMessage: String?
3867

68+
var source: SignInSource?
69+
3970
private var rows = [Row]()
4071
private var buttonViewController: NUXButtonViewController?
4172
private let configuration = WordPressAuthenticator.shared.configuration
@@ -509,14 +540,15 @@ private extension GetStartedViewController {
509540
// username instead.
510541
self.showSelfHostedWithError(error)
511542
} else {
543+
let signInError = SignInError(error: error, source: source) ?? error
512544
guard let authenticationDelegate = WordPressAuthenticator.shared.delegate,
513-
authenticationDelegate.shouldHandleError(error) else {
514-
self.displayError(error as NSError, sourceTag: self.sourceTag)
545+
authenticationDelegate.shouldHandleError(signInError) else {
546+
displayError(error as NSError, sourceTag: sourceTag)
515547
return
516548
}
517549

518550
/// Hand over control to the host app.
519-
authenticationDelegate.handleError(error) { customUI in
551+
authenticationDelegate.handleError(signInError) { customUI in
520552
// Setting the rightBarButtonItems of the custom UI before pushing the view controller
521553
// and resetting the navigationController's navigationItem after the push seems to be the
522554
// only combination that gets the Help button to show up.

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ private extension SiteAddressViewController {
588588
DDLogError("Failed to navigate from SiteAddressViewController to GetStartedViewController")
589589
return
590590
}
591+
vc.source = .wpComSiteAddress
591592

592593
vc.loginFields = loginFields
593594
vc.dismissBlock = dismissBlock

0 commit comments

Comments
 (0)