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

Commit b039eb8

Browse files
authored
Merge pull request #5 from wordpress-mobile/fix/wpcom-restriction-in-social-error
Hide address-based option in social errors
2 parents d0b3c02 + f219e8e commit b039eb8

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public struct WordPressAuthenticatorConfiguration {
254254
let storyboard = UIStoryboard(name: "Login", bundle: bundle)
255255
if let controller = storyboard.instantiateInitialViewController() {
256256
if let childController = controller.childViewControllers.first as? LoginPrologueViewController {
257-
childController.restrictToWPCom = restrictToWPCom
257+
childController.loginFields.restrictToWPCom = restrictToWPCom
258258
childController.showCancel = showCancel
259259
}
260260
presenter.present(controller, animated: animated, completion: nil)
@@ -272,7 +272,7 @@ public struct WordPressAuthenticatorConfiguration {
272272
return
273273
}
274274

275-
controller.restrictToWPCom = true
275+
controller.loginFields.restrictToWPCom = true
276276
controller.loginFields.meta.jetpackBlogXMLRPC = xmlrpc
277277
controller.loginFields.meta.jetpackBlogUsername = username
278278

WordPressAuthenticator/Model/LoginFields.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class LoginFields: NSObject {
3030
/// User ID for use with the nonce for social login
3131
@objc public var nonceUserID: Int = 0
3232

33+
/// Used to restrict login to WordPress.com
34+
public var restrictToWPCom = false
35+
3336
/// Used by the SignupViewController. Signup currently asks for both a
3437
/// username and an email address. This can be factored away when we revamp
3538
/// the signup flow.

WordPressAuthenticator/Signin/LoginEmailViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
9393
///
9494
func configureForWPComOnlyIfNeeded() {
9595
wpcomSignupButton?.isHidden = !offerSignupOption
96-
selfHostedLoginButton?.isHidden = restrictToWPCom
96+
selfHostedLoginButton?.isHidden = loginFields.restrictToWPCom
9797
}
9898

9999

@@ -386,6 +386,7 @@ class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
386386
let socialErrorVC = LoginSocialErrorViewController(title: errorTitle, description: errorDescription)
387387
let socialErrorNav = LoginNavigationController(rootViewController: socialErrorVC)
388388
socialErrorVC.delegate = self
389+
socialErrorVC.loginFields = loginFields
389390
present(socialErrorNav, animated: true) {}
390391
} else {
391392
errorToPresent = error

WordPressAuthenticator/Signin/LoginSocialErrorViewController.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class LoginSocialErrorViewController: NUXTableViewController {
2929
case tryEmail = 0
3030
case tryAddress = 1
3131
case signup = 2
32+
33+
static var count: Int {
34+
return signup.rawValue + 1
35+
}
3236
}
3337

3438
/// Create and instance of LoginSocialErrorViewController
@@ -67,7 +71,11 @@ class LoginSocialErrorViewController: NUXTableViewController {
6771
case Buttons.tryEmail.rawValue:
6872
delegate.retryWithEmail()
6973
case Buttons.tryAddress.rawValue:
70-
delegate.retryWithAddress()
74+
if loginFields.restrictToWPCom {
75+
fallthrough
76+
} else {
77+
delegate.retryWithAddress()
78+
}
7179
case Buttons.signup.rawValue:
7280
fallthrough
7381
default:
@@ -98,8 +106,8 @@ extension LoginSocialErrorViewController {
98106
// MARK: UITableViewDataSource methods
99107

100108
extension LoginSocialErrorViewController {
101-
private struct Constants {
102-
static let buttonCount = 3
109+
private func numberOfButtonsToShow() -> Int {
110+
return loginFields.restrictToWPCom ? Buttons.count - 1 : Buttons.count
103111
}
104112

105113
override func numberOfSections(in tableView: UITableView) -> Int {
@@ -111,7 +119,7 @@ extension LoginSocialErrorViewController {
111119
case Sections.titleAndDescription.rawValue:
112120
return 1
113121
case Sections.buttons.rawValue:
114-
return Constants.buttonCount
122+
return numberOfButtonsToShow()
115123
default:
116124
return 0
117125
}
@@ -153,8 +161,12 @@ extension LoginSocialErrorViewController {
153161
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")
154162
buttonIcon = Gridicon.iconOfType(.undo)
155163
case Buttons.tryAddress.rawValue:
156-
buttonText = NSLocalizedString("Try with the site address", comment: "When social login fails, this button offers to let them try tp login using a URL")
157-
buttonIcon = Gridicon.iconOfType(.domains)
164+
if loginFields.restrictToWPCom {
165+
fallthrough
166+
} else {
167+
buttonText = NSLocalizedString("Try with the site address", comment: "When social login fails, this button offers to let them try tp login using a URL")
168+
buttonIcon = Gridicon.iconOfType(.domains)
169+
}
158170
case Buttons.signup.rawValue:
159171
fallthrough
160172
default:

WordPressAuthenticator/Signin/LoginViewController.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import WordPressKit
66
class LoginViewController: NUXViewController, LoginFacadeDelegate {
77
@IBOutlet var instructionLabel: UILabel?
88
@objc var errorToPresent: Error?
9-
var restrictToWPCom = false
109

1110
lazy var loginFacade: LoginFacade = {
1211
let configuration = WordPressAuthenticator.shared.configuration
@@ -142,7 +141,6 @@ class LoginViewController: NUXViewController, LoginFacadeDelegate {
142141
}
143142

144143
destination.loginFields = source.loginFields
145-
destination.restrictToWPCom = source.restrictToWPCom
146144
destination.dismissBlock = source.dismissBlock
147145
destination.errorToPresent = source.errorToPresent
148146
}

WordPressAuthenticator/Signup/SignupEmailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class SignupEmailViewController: LoginViewController, NUXKeyboardResponder {
165165
super.prepare(for: segue, sender: sender)
166166
// Configure login flow to allow only .com login and prefill the email
167167
if let destination = segue.destination as? LoginEmailViewController {
168-
destination.restrictToWPCom = true
168+
destination.loginFields.restrictToWPCom = true
169169
destination.loginFields.username = loginFields.emailAddress
170170
}
171171
}

0 commit comments

Comments
 (0)