Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pod::Spec.new do |s|
s.name = 'WordPressAuthenticator'
s.version = '2.1.0-beta.3'
s.version = '2.1.0-beta.4'

s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private extension NavigateToEnterAccount {
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
return
}
vc.source = .wpCom

navigationController?.pushViewController(vc, animated: true)
}
Expand Down
10 changes: 1 addition & 9 deletions WordPressAuthenticator/Signin/LoginPrologueViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class LoginPrologueViewController: LoginViewController {
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
return
}
vc.source = .wpCom

navigationController?.pushViewController(vc, animated: true)
}
Expand Down Expand Up @@ -436,15 +437,6 @@ class LoginPrologueViewController: LoginViewController {
navigationController?.pushViewController(toVC, animated: true)
}

private func presentGetStartedView() {
guard let toVC = GetStartedViewController.instantiate(from: .getStarted) else {
DDLogError("Failed to navigate to GetStartedViewController")
return
}

navigationController?.pushViewController(toVC, animated: true)
}

Comment on lines -439 to -447
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to make a note on this, this is dead code 😅 I was checking where GetStartedViewController is initialized in WPAuthenticator, and thought it's good to remove any unused code.

// Shows the VC that handles both Google login & signup.
private func presentUnifiedGoogleView() {
guard let toVC = GoogleAuthViewController.instantiate(from: .googleAuth) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@ import UIKit
import SafariServices
import WordPressKit

/// The source for the sign in flow for external tracking.
public enum SignInSource {
/// Initiated from the WP.com login CTA.
case wpCom
/// Initiated from the WP.com login flow that starts with site address.
case wpComSiteAddress
}

/// The error during the sign in flow.
public enum SignInError: Error {
case invalidWPComEmail(source: SignInSource)

init?(error: Error, source: SignInSource?) {
let error = error as NSError

switch error.code {
case WordPressComRestApiError.unknown.rawValue:
let restAPIErrorCode = error.userInfo[WordPressComRestApi.ErrorKeyErrorCode] as? String
if let source = source, restAPIErrorCode == "unknown_user" {
self = .invalidWPComEmail(source: source)
} else {
return nil
}
default:
return nil
}
}
}

class GetStartedViewController: LoginViewController, NUXKeyboardResponder {

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

var source: SignInSource?

private var rows = [Row]()
private var buttonViewController: NUXButtonViewController?
private let configuration = WordPressAuthenticator.shared.configuration
Expand Down Expand Up @@ -509,14 +540,15 @@ private extension GetStartedViewController {
// username instead.
self.showSelfHostedWithError(error)
} else {
let signInError = SignInError(error: error, source: source) ?? error
guard let authenticationDelegate = WordPressAuthenticator.shared.delegate,
authenticationDelegate.shouldHandleError(error) else {
self.displayError(error as NSError, sourceTag: self.sourceTag)
authenticationDelegate.shouldHandleError(signInError) else {
displayError(error as NSError, sourceTag: sourceTag)
return
}

/// Hand over control to the host app.
authenticationDelegate.handleError(error) { customUI in
authenticationDelegate.handleError(signInError) { customUI in
// Setting the rightBarButtonItems of the custom UI before pushing the view controller
// and resetting the navigationController's navigationItem after the push seems to be the
// only combination that gets the Help button to show up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ private extension SiteAddressViewController {
DDLogError("Failed to navigate from SiteAddressViewController to GetStartedViewController")
return
}
vc.source = .wpComSiteAddress

vc.loginFields = loginFields
vc.dismissBlock = dismissBlock
Expand Down