Skip to content

Commit

Permalink
Merge pull request #154 from wordpress-mobile/issue/12779-black-flagg…
Browse files Browse the repository at this point in the history
…ed-websites-woo

[Woo] Allow signing in to WPCom black-flagged websites using site credentials
  • Loading branch information
hichamboushaba authored Oct 18, 2024
2 parents ac70b6d + 500238c commit cb4a9fe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.wordpress.android.login

data class ConnectSiteInfoResult @JvmOverloads constructor(
val url: String,
val urlAfterRedirects: String?,
val hasJetpack: Boolean,
/**
* Whether the site is suspended on WordPress.com and can't be connected using Jetpack
*/
val isWPComSuspended: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ void needs2faSocial(String email, String userId, String nonceAuthenticator, Stri
// Login Site Address input callbacks
void alreadyLoggedInWpcom(ArrayList<Integer> oldSitesIds);
void gotWpcomSiteInfo(String siteAddress);
void gotConnectedSiteInfo(@NonNull String siteAddress, @Nullable String redirectUrl, boolean hasJetpack);
default void gotConnectSiteInfo(@NonNull ConnectSiteInfoResult result) {
gotConnectedSiteInfo(result.getUrl(), result.getUrlAfterRedirects(), result.getHasJetpack());
}

default void gotConnectedSiteInfo(@NonNull String siteAddress, @Nullable String redirectUrl, boolean hasJetpack) { }
void gotXmlRpcEndpoint(String inputSiteAddress, String endpointAddress);
void handleSslCertificateError(MemorizingTrustManager memorizingTrustManager, SelfSignedSSLCallback callback);
void helpSiteAddress(String url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.SiteStore.ConnectSiteInfoPayload;
import org.wordpress.android.fluxc.store.SiteStore.OnConnectSiteInfoChecked;
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType;
import org.wordpress.android.login.util.SiteUtils;
import org.wordpress.android.login.widgets.WPLoginInputRow;
import org.wordpress.android.login.widgets.WPLoginInputRow.OnEditorCommitListener;
Expand Down Expand Up @@ -339,15 +340,7 @@ public void handleDiscoverySuccess(@NonNull String endpointAddress) {
// hold the URL in a variable to use below otherwise it gets cleared up by endProgress
String inputSiteAddress = mRequestedSiteAddress;
endProgress();
if (mLoginListener.getLoginMode() == LoginMode.WOO_LOGIN_MODE) {
mLoginListener.gotConnectedSiteInfo(
mConnectSiteInfoUrl,
mConnectSiteInfoUrlRedirect,
mConnectSiteInfoCalculatedHasJetpack
);
} else {
mLoginListener.gotXmlRpcEndpoint(inputSiteAddress, endpointAddress);
}
mLoginListener.gotXmlRpcEndpoint(inputSiteAddress, endpointAddress);
}

private void askForHttpAuthCredentials(@NonNull final String url, int messageId) {
Expand Down Expand Up @@ -397,13 +390,26 @@ public void onFetchedConnectSiteInfo(OnConnectSiteInfoChecked event) {
event.error.type.name(),
event.error.message);

AppLog.e(T.API, "onFetchedConnectSiteInfo has error: " + event.error.message);
if (NetworkUtils.isNetworkAvailable(requireContext())) {
showError(R.string.invalid_site_url_message);
if (event.error.type == SiteErrorType.WPCOM_SITE_SUSPENDED
&& mLoginListener.getLoginMode() == LoginMode.WOO_LOGIN_MODE) {
// the site is WPCom suspended, we should treat it as non-Jetpack site
mConnectSiteInfoCalculatedHasJetpack = false;
mLoginListener.gotConnectSiteInfo(
new ConnectSiteInfoResult(
mRequestedSiteAddress,
null,
mConnectSiteInfoCalculatedHasJetpack,
true
)
);
} else {
showError(R.string.error_generic_network);
AppLog.e(T.API, "onFetchedConnectSiteInfo has error: " + event.error.message);
if (NetworkUtils.isNetworkAvailable(requireContext())) {
showError(R.string.invalid_site_url_message);
} else {
showError(R.string.error_generic_network);
}
}

endProgressIfNeeded();
} else {
boolean hasJetpack = calculateHasJetpack(event.info);
Expand Down Expand Up @@ -433,10 +439,12 @@ private void handleConnectSiteInfoForWoo(ConnectSiteInfoPayload siteInfo) {
mLoginListener.handleSiteAddressError(siteInfo);
} else {
endProgressIfNeeded();
mLoginListener.gotConnectedSiteInfo(
mConnectSiteInfoUrl,
mConnectSiteInfoUrlRedirect,
mConnectSiteInfoCalculatedHasJetpack
mLoginListener.gotConnectSiteInfo(
new ConnectSiteInfoResult(
mConnectSiteInfoUrl,
mConnectSiteInfoUrlRedirect,
mConnectSiteInfoCalculatedHasJetpack
)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ext {
// libs
wordpressLintVersion = '2.1.0'
wordpressUtilsVersion = '3.5.0'
wordpressFluxCVersion = 'trunk-863f213e0e3a7a4322032e8e8c57a99f77bb48ec'
wordpressFluxCVersion = 'trunk-5dfbbc993d2472f6aad2b9f357021506ecfe7152'
gravatarSdkVersion = '0.2.0'

// main
Expand Down

0 comments on commit cb4a9fe

Please sign in to comment.