Skip to content

Commit daff737

Browse files
Merge pull request #7320 from woocommerce/feat/7298-site-cred-login
[Login] - Introduce a way to sign in using store credentials.
2 parents b0a44f6 + 5234a6b commit daff737

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ target 'WooCommerce' do
4242
pod 'Gridicons', '~> 1.2.0'
4343

4444
# To allow pod to pick up beta versions use -beta. E.g., 1.1.7-beta.1
45-
pod 'WordPressAuthenticator', '~> 2.0.1'
45+
pod 'WordPressAuthenticator', '~> 2.1.0-beta.3'
4646
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => ''
4747
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :branch => ''
4848
# pod 'WordPressAuthenticator', :path => '../WordPressAuthenticator-iOS'

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PODS:
4242
- WordPress-Aztec-iOS (1.11.0)
4343
- WordPress-Editor-iOS (1.11.0):
4444
- WordPress-Aztec-iOS (= 1.11.0)
45-
- WordPressAuthenticator (2.0.1):
45+
- WordPressAuthenticator (2.1.0-beta.3):
4646
- Alamofire (~> 4.8)
4747
- CocoaLumberjack (~> 3.5)
4848
- GoogleSignIn (~> 6.0.1)
@@ -92,7 +92,7 @@ DEPENDENCIES:
9292
- Sourcery (~> 1.0.3)
9393
- StripeTerminal (~> 2.7)
9494
- WordPress-Editor-iOS (~> 1.11.0)
95-
- WordPressAuthenticator (~> 2.0.1)
95+
- WordPressAuthenticator (~> 2.1.0-beta.3)
9696
- WordPressKit (~> 4.49.0)
9797
- WordPressShared (~> 1.15)
9898
- WordPressUI (~> 1.12.5)
@@ -163,7 +163,7 @@ SPEC CHECKSUMS:
163163
UIDeviceIdentifier: af4e11e25a2ea670078e2bd677bb0e8144f9f063
164164
WordPress-Aztec-iOS: 050b34d4c3adfb7c60363849049b13d60683b348
165165
WordPress-Editor-iOS: 304098424f1051cb271546c99f906aac296b1b81
166-
WordPressAuthenticator: 7f41297c3ac33ff19a65cb84950c6260932e47c0
166+
WordPressAuthenticator: 5882d5ba6084a20c0e660950363e456162a11296
167167
WordPressKit: 96deb6ba37ea5eaec4ddcaa53eca04d653246152
168168
WordPressShared: 5477f179c7fe03b5d574f91adda66f67d131827e
169169
WordPressUI: c5be816f6c7b3392224ac21de9e521e89fa108ac
@@ -179,6 +179,6 @@ SPEC CHECKSUMS:
179179
ZendeskSupportProvidersSDK: 2bdf8544f7cd0fd4c002546f5704b813845beb2a
180180
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
181181

182-
PODFILE CHECKSUM: 3112ab60d6ff0779572bbc86e380a622138ccc64
182+
PODFILE CHECKSUM: 918b977da8de7fa51654420e8011f30808657095
183183

184184
COCOAPODS: 1.11.2

RELEASE-NOTES.txt

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

33
9.8
44
-----
5+
- [***] Login: Introduce a way to sign in using store credentials. [https://github.com/woocommerce/woocommerce-ios/pull/7320]
56
- [*] In-Person Payments: The purchase card reader information card appears also in the Orders list screen. [https://github.com/woocommerce/woocommerce-ios/pull/7326]
67

78
9.7

WooCommerce/Classes/Authentication/AuthenticationConstants.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct AuthenticationConstants {
2121
/// What is WordPress.com? link (Continue with WordPress.com)
2222
///
2323
static let whatIsWPComLinkTitle = NSLocalizedString(
24-
"_What is WordPress.com?_",
25-
comment: "Navigates to page with details about What is WordPress.com. The underscores _..._ denote underline."
24+
"What is WordPress.com?",
25+
comment: "Navigates to page with details about What is WordPress.com."
2626
)
2727

2828
/// Login with Jetpack instructions.
@@ -58,6 +58,13 @@ struct AuthenticationConstants {
5858
comment: "Button title. Takes the user to the login by store address flow."
5959
)
6060

61+
/// Title of "Sign in with store credentials" button
62+
//
63+
static let signInWithSiteCredsButtonTitle = NSLocalizedString(
64+
"Sign in with store credentials",
65+
comment: "Button title. Takes the user to the site credentials entry screen."
66+
)
67+
6168
/// Title of views in Unified Login
6269
//
6370
static let loginTitle = NSLocalizedString(

WooCommerce/Classes/Authentication/AuthenticationManager.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class AuthenticationManager: Authentication {
4545
enableSignInWithApple: true,
4646
enableSignupWithGoogle: false,
4747
enableUnifiedAuth: true,
48-
continueWithSiteAddressFirst: true)
48+
continueWithSiteAddressFirst: true,
49+
enableSiteCredentialsLoginForSelfHostedSites: true,
50+
isWPComLoginRequiredForSiteCredentialsLogin: true)
4951

5052
let systemGray3LightModeColor = UIColor(red: 199/255.0, green: 199/255.0, blue: 204/255.0, alpha: 1)
5153
let systemLabelLightModeColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
@@ -85,6 +87,7 @@ class AuthenticationManager: Authentication {
8587
usernamePasswordInstructions: AuthenticationConstants.usernamePasswordInstructions,
8688
continueWithWPButtonTitle: AuthenticationConstants.continueWithWPButtonTitle,
8789
enterYourSiteAddressButtonTitle: AuthenticationConstants.enterYourSiteAddressButtonTitle,
90+
signInWithSiteCredentialsButtonTitle: AuthenticationConstants.signInWithSiteCredsButtonTitle,
8891
findSiteButtonTitle: AuthenticationConstants.findYourStoreAddressButtonTitle,
8992
signupTermsOfService: AuthenticationConstants.signupTermsOfService,
9093
whatIsWPComLinkTitle: AuthenticationConstants.whatIsWPComLinkTitle,
@@ -260,6 +263,15 @@ extension AuthenticationManager: WordPressAuthenticatorDelegate {
260263
/// Presents the Login Epilogue, in the specified NavigationController.
261264
///
262265
func presentLoginEpilogue(in navigationController: UINavigationController, for credentials: AuthenticatorCredentials, onDismiss: @escaping () -> Void) {
266+
let matcher = ULAccountMatcher()
267+
matcher.refreshStoredSites()
268+
269+
/// Jetpack is required. Present an error if we don't detect a valid installation for a self-hosted site.
270+
if let urlFromCredentials = credentials.wpcom?.siteURL ?? credentials.wporg?.siteURL,
271+
isJetpackValidForSelfHostedSite(url: urlFromCredentials) {
272+
return presentJetpackError(for: urlFromCredentials, with: credentials, in: navigationController, onDismiss: onDismiss)
273+
}
274+
263275
// We are currently supporting WPCom credentials only
264276
// Update this when handling store credentials authentication.
265277
guard let wpcomLogin = credentials.wpcom else {
@@ -270,16 +282,7 @@ extension AuthenticationManager: WordPressAuthenticatorDelegate {
270282
ServiceLocator.pushNotesManager.cancelLocalNotification(scenarios: [.loginSiteAddressError])
271283
}
272284

273-
let matcher = ULAccountMatcher()
274-
matcher.refreshStoredSites()
275-
276285
guard matcher.match(originalURL: wpcomLogin.siteURL) else {
277-
278-
/// Jetpack is required. Present an error if we don't detect a valid installation for a self-hosted site.
279-
if isJetpackValidForSelfHostedSite(url: wpcomLogin.siteURL) {
280-
return presentJetpackError(for: wpcomLogin.siteURL, with: credentials, in: navigationController, onDismiss: onDismiss)
281-
}
282-
283286
DDLogWarn("⚠️ Present account mismatch error for site: \(String(describing: credentials.wpcom?.siteURL))")
284287
let viewModel = WrongAccountErrorViewModel(siteURL: credentials.wpcom?.siteURL)
285288
let mismatchAccountUI = ULAccountMismatchViewController(viewModel: viewModel)
@@ -447,6 +450,7 @@ private extension AuthenticationManager {
447450
in navigationController: UINavigationController,
448451
onDismiss: @escaping () -> Void) {
449452
let viewModel = JetpackErrorViewModel(siteURL: siteURL, onJetpackSetupCompletion: { [weak self] in
453+
self?.currentSelfHostedSite = nil
450454
self?.presentLoginEpilogue(in: navigationController, for: credentials, onDismiss: onDismiss)
451455
})
452456
let installJetpackUI = ULErrorViewController(viewModel: viewModel)

WooCommerce/WooCommerceTests/Authentication/AuthenticationManagerTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,22 @@ final class AuthenticationManagerTests: XCTestCase {
172172
let rootController = navigationController.viewControllers.first
173173
XCTAssertTrue(rootController is ULErrorViewController)
174174
}
175+
176+
func test_it_can_display_jetpack_error_for_org_site_credentials_sign_in() {
177+
// Given
178+
let manager = AuthenticationManager()
179+
let testSite = "http://test.com"
180+
let siteInfo = WordPressComSiteInfo(remote: ["isWordPress": true, "hasJetpack": false, "urlAfterRedirects": testSite])
181+
let wporgCredentials = WordPressOrgCredentials(username: "cba", password: "password", xmlrpc: "http://test.com/xmlrpc.php", options: [:])
182+
let credentials = AuthenticatorCredentials(wpcom: nil, wporg: wporgCredentials)
183+
let navigationController = UINavigationController()
184+
185+
// When
186+
manager.shouldPresentUsernamePasswordController(for: siteInfo, onCompletion: { _ in })
187+
manager.presentLoginEpilogue(in: navigationController, for: credentials, onDismiss: {})
188+
189+
// Then
190+
let rootController = navigationController.viewControllers.first
191+
XCTAssertTrue(rootController is ULErrorViewController)
192+
}
175193
}

0 commit comments

Comments
 (0)