Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge login lib changes and implement new interface methods #10150

Merged
merged 8 commits into from
Jul 16, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,12 @@ private void dismissSignupSheet() {
public AndroidInjector<Fragment> supportFragmentInjector() {
return mFragmentInjector;
}

@Override public void showHelpFindingConnectedEmail() {
// Not used in WordPress app
}

@Override public void gotConnectedSiteInfo(String siteAddress, boolean hasJetpack) {
// Not used in WordPress app
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,18 @@ public void trackUsernamePasswordFormViewed() {
public void trackWpComBackgroundServiceUpdate(Map<String, ?> properties) {
AnalyticsTracker.track(AnalyticsTracker.Stat.LOGIN_WPCOM_BACKGROUND_SERVICE_UPDATE, properties);
}

@Override public void trackConnectedSiteInfoRequested(String url) {
// Not used in WordPress app
}

@Override
public void trackConnectedSiteInfoFailed(String url, String errorContext, String errorType,
String errorDescription) {
// Not used in WordPress app
}

@Override public void trackConnectedSiteInfoSucceeded(Map<String, ?> properties) {
// Not used in WordPress app
}
}
3 changes: 3 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@
<string name="enter_your_password_instead">Enter your password instead</string>
<string name="alternatively">Alternatively:</string>
<string name="enter_email_wordpress_com">Log in to WordPress.com using an email address to manage all your WordPress sites.</string>
<string name="enter_email_for_site">Log in with WordPress.com to connect to %1$s</string>
<string name="next">Next</string>
<string name="open_mail">Open mail</string>
<string name="enter_site_address_instead">Log in by entering your site address.</string>
Expand Down Expand Up @@ -2320,6 +2321,8 @@
<string name="login_error_generic_start">Google login could not be started.</string>
<string name="login_error_suffix">\nMaybe try a different account?</string>
<string name="enter_wpcom_or_jetpack_site">Please enter a WordPress.com or Jetpack-connected self-hosted WordPress site</string>
<string name="enter_wordpress_site">The website at this address is not a WordPress site. For us to connect to it, the site must have WordPress installed.</string>
<string name="login_need_help_finding_connected_email">Need help finding the email you connected with?</string>
<!-- Screen titles -->
<string name="email_address_login_title">Email address login</string>
<string name="site_address_login_title">Site address login</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ public interface LoginAnalyticsListener {
void trackUrlHelpScreenViewed();
void trackUsernamePasswordFormViewed();
void trackWpComBackgroundServiceUpdate(Map<String, ?> properties);
void trackConnectedSiteInfoRequested(String url);
void trackConnectedSiteInfoFailed(String url, String errorContext, String errorType, String errorDescription);
void trackConnectedSiteInfoSucceeded(Map<String, ?> properties);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.login;

import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
private static final int GOOGLE_API_CLIENT_ID = 1002;
private static final int EMAIL_CREDENTIALS_REQUEST_CODE = 25100;

private static final String ARG_HIDE_LOGIN_BY_SITE_OPTION = "ARG_HIDE_LOGIN_BY_SITE_OPTION";
private static final String ARG_LOGIN_SITE_URL = "ARG_LOGIN_SITE_URL";

public static final String TAG = "login_email_fragment_tag";
public static final int MAX_EMAIL_LENGTH = 100;

Expand All @@ -79,6 +83,17 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
protected WPLoginInputRow mEmailInput;
protected boolean mHasDismissedEmailHints;
protected boolean mIsDisplayingEmailHints;
protected boolean mHideLoginWithSiteOption;
protected String mLoginSiteUrl;

public static LoginEmailFragment newInstance(Boolean hideLoginWithSiteOption, String url) {
LoginEmailFragment fragment = new LoginEmailFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_HIDE_LOGIN_BY_SITE_OPTION, hideLoginWithSiteOption);
args.putString(ARG_LOGIN_SITE_URL, url);
fragment.setArguments(args);
return fragment;
}

@Override
protected @LayoutRes int getContentLayout() {
Expand All @@ -103,6 +118,9 @@ protected void setupLabel(@NonNull TextView label) {
case WPCOM_LOGIN_ONLY:
label.setText(R.string.enter_email_wordpress_com);
break;
case WOO_LOGIN_MODE:
label.setText(getString(R.string.enter_email_for_site, mLoginSiteUrl));
break;
case JETPACK_STATS:
label.setText(R.string.login_to_to_connect_jetpack);
break;
Expand Down Expand Up @@ -162,25 +180,30 @@ public void onClick(View view) {
});

LinearLayout siteLoginButton = rootView.findViewById(R.id.login_site_button);
siteLoginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mLoginListener != null) {
if (mLoginListener.getLoginMode() == LoginMode.JETPACK_STATS) {
mLoginListener.loginViaWpcomUsernameInstead();
} else {
mLoginListener.loginViaSiteAddress();
if (mHideLoginWithSiteOption) {
siteLoginButton.setVisibility(View.GONE);
} else {
siteLoginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mLoginListener != null) {
if (mLoginListener.getLoginMode() == LoginMode.JETPACK_STATS) {
mLoginListener.loginViaWpcomUsernameInstead();
} else {
mLoginListener.loginViaSiteAddress();
}
}
}
}
});
});
}

ImageView siteLoginButtonIcon = rootView.findViewById(R.id.login_site_button_icon);
TextView siteLoginButtonText = rootView.findViewById(R.id.login_site_button_text);

switch (mLoginListener.getLoginMode()) {
case FULL:
case WPCOM_LOGIN_ONLY:
case WOO_LOGIN_MODE:
case SHARE_INTENT:
siteLoginButtonIcon.setImageResource(R.drawable.ic_domains_grey_24dp);
siteLoginButtonText.setText(R.string.enter_site_address_instead);
Expand Down Expand Up @@ -211,6 +234,13 @@ public void onClick(View view) {
}
}
});
} else if (mLoginListener.getLoginMode() == LoginMode.WOO_LOGIN_MODE) {
secondaryButton.setText(getResources().getString(R.string.login_need_help_finding_connected_email));
secondaryButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
mLoginListener.showHelpFindingConnectedEmail();
}
});
} else {
secondaryButton.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -244,6 +274,13 @@ public void onAttach(Context context) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle args = getArguments();
if (args != null) {
mHideLoginWithSiteOption = args.getBoolean(ARG_HIDE_LOGIN_BY_SITE_OPTION, false);
mLoginSiteUrl = args.getString(ARG_LOGIN_SITE_URL, "");
}

mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(LoginEmailFragment.this)
.enableAutoManage(getActivity(), GOOGLE_API_CLIENT_ID, LoginEmailFragment.this)
Expand Down Expand Up @@ -445,6 +482,8 @@ public void getEmailHints() {
startIntentSenderForResult(intent.getIntentSender(), EMAIL_CREDENTIALS_REQUEST_CODE, null, 0, 0, 0, null);
} catch (IntentSender.SendIntentException exception) {
AppLog.d(T.NUX, LOG_TAG + "Could not start email hint picker" + exception);
} catch (ActivityNotFoundException exception) {
AppLog.d(T.NUX, LOG_TAG + "Could not find any activity to handle email hint picker" + exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface SelfSignedSSLCallback {
void helpEmailScreen(String email);
void helpSocialEmailScreen(String email);
void addGoogleLoginFragment();
void showHelpFindingConnectedEmail();

// Login Request Magic Link callbacks
void showMagicLinkSentScreen(String email);
Expand All @@ -47,6 +48,7 @@ interface SelfSignedSSLCallback {
// Login Site Address input callbacks
void alreadyLoggedInWpcom(ArrayList<Integer> oldSitesIds);
void gotWpcomSiteInfo(String siteAddress, String siteName, String siteIconUrl);
void gotConnectedSiteInfo(String siteAddress, 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 @@ -9,7 +9,8 @@ public enum LoginMode {
JETPACK_STATS,
WPCOM_LOGIN_DEEPLINK,
WPCOM_REAUTHENTICATE,
SHARE_INTENT;
SHARE_INTENT,
WOO_LOGIN_MODE;

private static final String ARG_LOGIN_MODE = "ARG_LOGIN_MODE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.wordpress.android.fluxc.network.discovery.SelfHostedEndpointFinder.DiscoveryError;
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.AccountStore.OnDiscoveryResponse;
import org.wordpress.android.fluxc.store.SiteStore.OnConnectSiteInfoChecked;
import org.wordpress.android.fluxc.store.SiteStore.OnWPComSiteFetched;
import org.wordpress.android.login.util.SiteUtils;
import org.wordpress.android.login.widgets.WPLoginInputRow;
Expand All @@ -40,6 +41,7 @@
import org.wordpress.android.util.UrlUtils;

import java.util.ArrayList;
import java.util.HashMap;

import javax.inject.Inject;

Expand Down Expand Up @@ -87,6 +89,9 @@ protected void setupContent(ViewGroup rootView) {
// important for accessibility - talkback
getActivity().setTitle(R.string.site_address_login_title);
mSiteAddressInput = rootView.findViewById(R.id.login_site_address_row);
if (BuildConfig.DEBUG) {
mSiteAddressInput.getEditText().setText(BuildConfig.DEBUG_WPCOM_WEBSITE_URL);
}
mSiteAddressInput.addTextChangedListener(this);
mSiteAddressInput.setOnEditorCommitListener(this);
}
Expand Down Expand Up @@ -163,7 +168,16 @@ protected void discover() {
mRequestedSiteAddress = cleanedSiteAddress;

String cleanedXmlrpcSuffix = UrlUtils.removeXmlrpcSuffix(mRequestedSiteAddress);
mDispatcher.dispatch(SiteActionBuilder.newFetchWpcomSiteByUrlAction(cleanedXmlrpcSuffix));

if (mLoginListener.getLoginMode() == LoginMode.WOO_LOGIN_MODE) {
// TODO: This is temporary code to test out sign in flow milestone 1 effectiveness. If we move
// forward with this flow, we will need to just call the XMLRPC discovery code and handle all the
// edge cases such as HTTP auth and self-signed SSL.
mAnalyticsListener.trackConnectedSiteInfoRequested(cleanedXmlrpcSuffix);
mDispatcher.dispatch(SiteActionBuilder.newFetchConnectSiteInfoAction(cleanedXmlrpcSuffix));
} else {
mDispatcher.dispatch(SiteActionBuilder.newFetchWpcomSiteByUrlAction(cleanedXmlrpcSuffix));
}

startProgress();
}
Expand Down Expand Up @@ -354,4 +368,65 @@ public void onDiscoverySucceeded(OnDiscoveryResponse event) {
AppLog.i(T.NUX, "Discovery succeeded, endpoint: " + event.xmlRpcEndpoint);
mLoginListener.gotXmlRpcEndpoint(requestedSiteAddress, event.xmlRpcEndpoint);
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onFetchedConnectSiteInfo(OnConnectSiteInfoChecked event) {
if (mRequestedSiteAddress == null) {
// bail if user canceled
return;
}

if (!isAdded()) {
return;
}

// hold the URL in a variable to use below otherwise it gets cleared up by endProgress
final String requestedSiteAddress = mRequestedSiteAddress;

if (isInProgress()) {
endProgress();
}

if (event.isError()) {
mAnalyticsListener.trackConnectedSiteInfoFailed(
requestedSiteAddress,
event.getClass().getSimpleName(),
event.error.type.name(),
event.error.message);

AppLog.e(T.API, "onFetchedConnectSiteInfo has error: " + event.error.message);

showError(R.string.invalid_site_url_message);
} else {
// TODO: If we plan to keep this logic we should convert these labels to constants
HashMap<String, String> properties = new HashMap<>();
properties.put("url", event.info.url);
properties.put("urlAfterRedirects", event.info.urlAfterRedirects);
properties.put("exists", Boolean.toString(event.info.exists));
properties.put("hasJetpack", Boolean.toString(event.info.hasJetpack));
properties.put("isJetpackActive", Boolean.toString(event.info.isJetpackActive));
properties.put("isJetpackConnected", Boolean.toString(event.info.isJetpackConnected));
properties.put("isWordPress", Boolean.toString(event.info.isWordPress));
properties.put("isWPCom", Boolean.toString(event.info.isWPCom));
mAnalyticsListener.trackConnectedSiteInfoSucceeded(properties);

if (!event.info.exists) {
// Site does not exist
showError(R.string.invalid_site_url_message);
} else if (!event.info.isWordPress) {
// Not a WordPress site
showError(R.string.enter_wordpress_site);
} else {
boolean hasJetpack = false;
if (event.info.isWPCom && event.info.hasJetpack) {
// This is likely an atomic site.
hasJetpack = true;
} else if (event.info.hasJetpack && event.info.isJetpackActive && event.info.isJetpackConnected) {
hasJetpack = true;
}
mLoginListener.gotConnectedSiteInfo(event.info.url, hasJetpack);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_large"
android:layout_marginBottom="@dimen/margin_extra_large"
android:textAlignment="viewStart"
android:gravity="start"
tools:text="@string/enter_site_address" />

<LinearLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
android:layout_marginBottom="@dimen/margin_extra_large"
android:layout_marginTop="@dimen/margin_extra_large"
android:layout_width="match_parent"
android:textAlignment="viewStart"
android:gravity="start"
tools:text="@string/enter_email_wordpress_com"
style="@style/LoginTheme.TextLabel" >
</TextView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
android:paddingEnd="@dimen/margin_medium_large"
android:layout_marginRight="@dimen/margin_extra_large"
android:layout_marginEnd="@dimen/margin_extra_large"
android:textAlignment="viewStart"
android:gravity="start|center_vertical"
tools:text="Secondary action"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_large"
android:textAlignment="viewStart"
android:gravity="start"
android:layout_marginBottom="@dimen/margin_extra_large"
tools:text="@string/enter_site_address" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<string name="login_promo_text_notifications">Your notifications travel with you — see comments and likes as they happen.</string>
<string name="login_promo_text_jetpack">Manage your Jetpack-powered site on the go — you\'ve got WordPress in your pocket.</string>
<string name="enter_email_wordpress_com">Log in to WordPress.com using an email address to manage all your WordPress sites.</string>
<string name="enter_email_for_site">Log in with WordPress.com to connect to %1$s</string>
<string name="next">Next</string>
<string name="open_mail">Open mail</string>
<string name="alternatively">Alternatively:</string>
Expand Down Expand Up @@ -100,7 +101,7 @@
site XMLRPC endpoint. The app needs that in order to communicate with your site. Contact your host to solve
this problem.</string>
<string name="enter_wpcom_or_jetpack_site">Please enter a WordPress.com or Jetpack-connected self-hosted WordPress site</string>

<string name="enter_wordpress_site">The website at this address is not a WordPress site. For us to connect to it, the site must have WordPress installed.</string>
<string name="error_generic_network">A network error occurred. Please check your connection and try again.</string>

<string name="notification_login_title_success">Logged in!</string>
Expand Down Expand Up @@ -139,4 +140,6 @@
<!-- Placeholder for notification channel to be used by login service notification.
This resource must be overwritten in the host project with a real notification channel id it has configured. -->
<string name="login_notification_channel_id">placeholder</string>

<string name="login_need_help_finding_connected_email">Need help finding the email you connected with?</string>
</resources>
1 change: 1 addition & 0 deletions libs/login/gradle.properties-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
wp.debug.wpcom_login_email =
wp.debug.wpcom_login_username =
wp.debug.wpcom_login_password =
wp.debug.wpcom_website_url =

android.useAndroidX=true
android.enableJetifier=true