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

Commit f591b6e

Browse files
Allow login for WPCOM suspended sites (#858)
2 parents c545aa5 + 1fd4b3e commit f591b6e

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _None._
3838

3939
### New Features
4040

41-
_None._
41+
- Add support for logging in into WPCOM suspended sites.
4242

4343
### Bug Fixes
4444

WordPressAuthenticator/Authenticator/WordPressAuthenticatorConfiguration.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public struct WordPressAuthenticatorConfiguration {
178178
///
179179
let enableSiteCreationGuide: Bool
180180

181+
/// If enabled allows login into sites marked as suspended in WordPress.com
182+
///
183+
let enableSiteCredentialsLoginForWPCOMSuspendedSites: Bool
184+
181185
/// Designated Initializer
182186
///
183187
public init (wpcomClientId: String,
@@ -215,7 +219,8 @@ public struct WordPressAuthenticatorConfiguration {
215219
enableManualErrorHandlingForSiteCredentialLogin: Bool = false,
216220
useEnterEmailAddressAsStepValueForGetStartedVC: Bool = false,
217221
enableSiteAddressLoginOnlyInPrologue: Bool = false,
218-
enableSiteCreationGuide: Bool = false
222+
enableSiteCreationGuide: Bool = false,
223+
enableSiteCredentialsLoginForWPCOMSuspendedSites: Bool = false
219224
) {
220225

221226
self.wpcomClientId = wpcomClientId
@@ -254,5 +259,6 @@ public struct WordPressAuthenticatorConfiguration {
254259
self.useEnterEmailAddressAsStepValueForGetStartedVC = useEnterEmailAddressAsStepValueForGetStartedVC
255260
self.enableSiteAddressLoginOnlyInPrologue = enableSiteAddressLoginOnlyInPrologue
256261
self.enableSiteCreationGuide = enableSiteCreationGuide
262+
self.enableSiteCredentialsLoginForWPCOMSuspendedSites = enableSiteCredentialsLoginForWPCOMSuspendedSites
257263
}
258264
}

WordPressAuthenticator/Model/WordPressComSiteInfo.swift

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public class WordPressComSiteInfo {
4444
///
4545
public let exists: Bool
4646

47+
public init(name: String, tagline: String, url: String, hasJetpack: Bool, isJetpackActive: Bool, isJetpackConnected: Bool, icon: String, isWPCom: Bool, isWP: Bool, exists: Bool) {
48+
self.name = name
49+
self.tagline = tagline
50+
self.url = url
51+
self.hasJetpack = hasJetpack
52+
self.isJetpackActive = isJetpackActive
53+
self.isJetpackConnected = isJetpackConnected
54+
self.icon = icon
55+
self.isWPCom = isWPCom
56+
self.isWP = isWP
57+
self.exists = exists
58+
}
59+
4760
/// Initializes the current SiteInfo instance with a raw dictionary.
4861
///
4962
public init(remote: [AnyHashable: Any]) {

WordPressAuthenticator/Services/WordPressComBlogService.swift

+22-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class WordPressComBlogService {
2020

2121
remote.fetchSiteInfo(forAddress: address, success: { response in
2222
guard let response = response else {
23-
failure(ServiceError.unknown)
23+
failure(WordPressComBlogServiceError.unknown)
2424
return
2525
}
2626

2727
let site = WordPressComSiteInfo(remote: response)
2828
success(site)
2929

3030
}, failure: { error in
31-
let result = error ?? ServiceError.unknown
31+
let result = error ?? WordPressComBlogServiceError.unknown
3232
failure(result)
3333
})
3434
}
@@ -37,18 +37,28 @@ class WordPressComBlogService {
3737
let remote = BlogServiceRemoteREST(wordPressComRestApi: anonymousAPI, siteID: 0)
3838
remote.fetchUnauthenticatedSiteInfo(forAddress: address, success: { response in
3939
guard let response = response else {
40-
failure(ServiceError.unknown)
40+
failure(WordPressComBlogServiceError.unknown)
4141
return
4242
}
4343

4444
let site = WordPressComSiteInfo(remote: response)
4545
guard site.url != Constants.wordPressBlogURL else {
46-
failure(ServiceError.invalidWordPressAddress)
46+
failure(WordPressComBlogServiceError.invalidWordPressAddress)
4747
return
4848
}
4949
success(site)
5050
}, failure: { error in
51-
let result = error ?? ServiceError.unknown
51+
let result: Error = {
52+
/// Check whether the site is suspended on WordPress.com and can't be connected using Jetpack
53+
///
54+
if let apiError = error as? WordPressAPIError<WordPressComRestApiEndpointError>,
55+
case let .endpointError(endpointError) = apiError,
56+
endpointError.apiErrorCode == "connection_disabled" {
57+
return WordPressComBlogServiceError.wpcomSiteSuspended
58+
}
59+
60+
return error ?? WordPressComBlogServiceError.unknown
61+
}()
5262
failure(result)
5363
})
5464
}
@@ -60,9 +70,12 @@ extension WordPressComBlogService {
6070
enum Constants {
6171
static let wordPressBlogURL = "https://wordpress.com/blog"
6272
}
73+
}
6374

64-
enum ServiceError: Error {
65-
case unknown
66-
case invalidWordPressAddress
67-
}
75+
public enum WordPressComBlogServiceError: Error {
76+
case unknown
77+
case invalidWordPressAddress
78+
/// Whether the site is suspended on WordPress.com and can't be connected using Jetpack
79+
///
80+
case wpcomSiteSuspended
6881
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,23 @@ private extension SiteAddressViewController {
552552
self?.navigationController?.pushViewController(customUI, animated: true)
553553
}
554554
} else {
555+
// Don't display error and allow login for suspended sites
556+
//
557+
if configuration.enableSiteCredentialsLoginForWPCOMSuspendedSites,
558+
let serviceError = error as? WordPressComBlogServiceError,
559+
serviceError == .wpcomSiteSuspended {
560+
successBlock(WordPressComSiteInfo(name: "",
561+
tagline: "",
562+
url: baseSiteUrl,
563+
hasJetpack: false,
564+
isJetpackActive: false,
565+
isJetpackConnected: false,
566+
icon: "",
567+
isWPCom: false,
568+
isWP: true,
569+
exists: true))
570+
return
571+
}
555572
self.displayError(message: Localization.invalidURL)
556573
}
557574
})

0 commit comments

Comments
 (0)