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
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public struct WordPressAuthenticatorConfiguration {
let storyboard = UIStoryboard(name: "Login", bundle: bundle)
if let controller = storyboard.instantiateInitialViewController() {
if let childController = controller.childViewControllers.first as? LoginPrologueViewController {
childController.restrictToWPCom = restrictToWPCom
childController.loginFields.restrictToWPCom = restrictToWPCom
childController.showCancel = showCancel
}
presenter.present(controller, animated: animated, completion: nil)
Expand All @@ -272,7 +272,7 @@ public struct WordPressAuthenticatorConfiguration {
return
}

controller.restrictToWPCom = true
controller.loginFields.restrictToWPCom = true
controller.loginFields.meta.jetpackBlogXMLRPC = xmlrpc
controller.loginFields.meta.jetpackBlogUsername = username

Expand Down
3 changes: 3 additions & 0 deletions WordPressAuthenticator/Model/LoginFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class LoginFields: NSObject {
/// User ID for use with the nonce for social login
@objc public var nonceUserID: Int = 0

/// Used to restrict login to WordPress.com
public var restrictToWPCom = false

/// Used by the SignupViewController. Signup currently asks for both a
/// username and an email address. This can be factored away when we revamp
/// the signup flow.
Expand Down
3 changes: 2 additions & 1 deletion WordPressAuthenticator/Signin/LoginEmailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
///
func configureForWPComOnlyIfNeeded() {
wpcomSignupButton?.isHidden = !offerSignupOption
selfHostedLoginButton?.isHidden = restrictToWPCom
selfHostedLoginButton?.isHidden = loginFields.restrictToWPCom
}


Expand Down Expand Up @@ -386,6 +386,7 @@ class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
let socialErrorVC = LoginSocialErrorViewController(title: errorTitle, description: errorDescription)
let socialErrorNav = LoginNavigationController(rootViewController: socialErrorVC)
socialErrorVC.delegate = self
socialErrorVC.loginFields = loginFields
present(socialErrorNav, animated: true) {}
} else {
errorToPresent = error
Expand Down
24 changes: 18 additions & 6 deletions WordPressAuthenticator/Signin/LoginSocialErrorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class LoginSocialErrorViewController: NUXTableViewController {
case tryEmail = 0
case tryAddress = 1
case signup = 2

static var count: Int {
return signup.rawValue + 1
}
}

/// Create and instance of LoginSocialErrorViewController
Expand Down Expand Up @@ -67,7 +71,11 @@ class LoginSocialErrorViewController: NUXTableViewController {
case Buttons.tryEmail.rawValue:
delegate.retryWithEmail()
case Buttons.tryAddress.rawValue:
delegate.retryWithAddress()
if loginFields.restrictToWPCom {
fallthrough
} else {
delegate.retryWithAddress()
}
case Buttons.signup.rawValue:
fallthrough
default:
Expand Down Expand Up @@ -98,8 +106,8 @@ extension LoginSocialErrorViewController {
// MARK: UITableViewDataSource methods

extension LoginSocialErrorViewController {
private struct Constants {
static let buttonCount = 3
private func numberOfButtonsToShow() -> Int {
return loginFields.restrictToWPCom ? Buttons.count - 1 : Buttons.count
}

override func numberOfSections(in tableView: UITableView) -> Int {
Expand All @@ -111,7 +119,7 @@ extension LoginSocialErrorViewController {
case Sections.titleAndDescription.rawValue:
return 1
case Sections.buttons.rawValue:
return Constants.buttonCount
return numberOfButtonsToShow()
default:
return 0
}
Expand Down Expand Up @@ -153,8 +161,12 @@ extension LoginSocialErrorViewController {
buttonText = NSLocalizedString("Try with another email", comment: "When social login fails, this button offers to let the user try again with a differen email address")
buttonIcon = Gridicon.iconOfType(.undo)
case Buttons.tryAddress.rawValue:
buttonText = NSLocalizedString("Try with the site address", comment: "When social login fails, this button offers to let them try tp login using a URL")
buttonIcon = Gridicon.iconOfType(.domains)
if loginFields.restrictToWPCom {
fallthrough
} else {
buttonText = NSLocalizedString("Try with the site address", comment: "When social login fails, this button offers to let them try tp login using a URL")
buttonIcon = Gridicon.iconOfType(.domains)
}
case Buttons.signup.rawValue:
fallthrough
default:
Expand Down
2 changes: 0 additions & 2 deletions WordPressAuthenticator/Signin/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import WordPressKit
class LoginViewController: NUXViewController, LoginFacadeDelegate {
@IBOutlet var instructionLabel: UILabel?
@objc var errorToPresent: Error?
var restrictToWPCom = false

lazy var loginFacade: LoginFacade = {
let configuration = WordPressAuthenticator.shared.configuration
Expand Down Expand Up @@ -142,7 +141,6 @@ class LoginViewController: NUXViewController, LoginFacadeDelegate {
}

destination.loginFields = source.loginFields
destination.restrictToWPCom = source.restrictToWPCom
destination.dismissBlock = source.dismissBlock
destination.errorToPresent = source.errorToPresent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class SignupEmailViewController: LoginViewController, NUXKeyboardResponder {
super.prepare(for: segue, sender: sender)
// Configure login flow to allow only .com login and prefill the email
if let destination = segue.destination as? LoginEmailViewController {
destination.restrictToWPCom = true
destination.loginFields.restrictToWPCom = true
destination.loginFields.username = loginFields.emailAddress
}
}
Expand Down