Skip to content

Commit

Permalink
Squashed 'libs/login/' changes from d3c0fa7ae4..4896a91c7c
Browse files Browse the repository at this point in the history
4896a91c7c Merge pull request #6 from wordpress-mobile/merge-wca
16a871bcf1 Set base button color to white
d6e2bf4184 Update login library default FluxC hash
7b3ba9e906 Merge commit 'e500cd63388ba77e7ea13df2fbb199c64e7107c2' into feature/import-latest-login-lib
0fe4cc1bf0 Merge commit '554b41f85535e113b1357e1c708fe304d50e0bd0' into develop
4495659338 Fix text of email not found error
ab65b7ea6e Fix text of sms throttled error
9f2e660eeb Checkstyle fix
61d3e7020e Refactoring
dd3989bbfa Refactoring
5cac71b526 Fix log msgs
42eb5f7300 Set image content description or mark it as not important for accessibility
bb0e745946 Fix checkstyle
0904ff17a5 Add a meaningful error message when the 2fa loggin is stopped because of sms throttling
606eb6fbe6 Trigger 2fa when the authentication SMS has been already sent during the flow
0f27a678d5 Fix google sign in flow
c98a1d473a Fix signup/in flows
30bf1accd1 Fix google sign-up
916621c9d7 Support setting the scheme in LoginMagicLinkRequestFragment
88e73ab293 Login integration
81fa3c9812 Add WP.com login as a step after Jetpack install
e3dd86f22b Localize the error message for invalid 2fa codes
08af882ab2 Merges release/10.2 into develop
7f9fca95f7 Update gradle plugin to 3.1.3
2520aa3844 Update google repository config and list it first
a88a7195ad Merge pull request #7880 from /issues/7856-refresh-meta-data
f2a12f0e4c fixed merge conflict
b218f90a2d Clean up from previous approach.
6ce03885e1 Remove errant space from login string
df7ae86a4d Update login library string to reflect core app string update
078c9c86f8 Remove unused strings from login library
51b07d7776 Tweak logic to allow a single method to bump acct created
17ede53ffc Overload method to have a shorter name.
33326b183b Refresh metadata for the google signup flow.
65c96baefa Call new method when bumping account created stat.
afedb2008a bumped google play services version to 15.0.1
853823cd9a Merge pull request #217 from woocommerce/feature/113-login-notification
848294dc29 Use more generic naming for the login notification channel id
fa437d344f Merge commit '09a0852581dd9a3a6b15109f3a8e9a80e644fbbb' into feature/update-login-library
6b07a925db Enable Google login
066beded26 Update gradle plugin to 3.1.2
3e1abf1cf0 Fix FluxC build error in login library
37707a744c Merge pull request #188 from woocommerce/feature/gradle-3.1.1
1a933195f0 Update gradle plugin and support libraries to latest
9af7502466 Update inner import checkstyle violations in login library
d07401c892 Update IDEA style config files
ad4fc3b429 Revert unintentional color change in the WordPressLoginFlow module.
c1b56716a1 Merge branch 'feature/order-details-screen' into feature/order-detail-views
6c93c92dc5 Exclude utils library from FluxC imports
372719093e Merge branch 'develop' into feature/order-detail-views
eec28986b5 Restore login notification styling changes
103dd8f6a1 Merge commit '6bd01d64a2d01176f5b26ae36836d4f5ff0fcdc9' into feature/update-login-lib
97462cca8e Merge branch 'develop' into feature/order-detail-views
20e9f3b9e3 Move login icon colors to variables
b15f6632fa Merge branch 'develop' into feature/114-login-style-refactor
26d1088134 Fix style violations in login library
17326beace Order Details - Customer Info View - Action Icons and listeners, updated icon assets * Add the ability to click to dial customer phone * Add the ability to click to email customer * Add the ability to click to sms customer
ebfa842faf Make login notification styling overridable
5494d0e742 Make login toolbar styling overridable
8cbdb5b313 Use overridable color names in login flow styles
e9137fe9f7 Replace WordPress buttons with LoginTheme
bf34dabb71 Expose play-services-auth dependency from login library
19203891d7 Merge commit '9751124a62caad5f7c9af772f8b872b604cd02b9' into feature/gradle-3.0
f5b58af6b4 Add WPCOM_LOGIN_ONLY LoginMode, disallowing self-hosted login

git-subtree-dir: libs/login
git-subtree-split: 4896a91c7cb62100a663fd879915eff73f39a27e
  • Loading branch information
aforcier committed Oct 18, 2018
1 parent 554b41f commit 1042a27
Show file tree
Hide file tree
Showing 34 changed files with 334 additions and 202 deletions.
14 changes: 10 additions & 4 deletions WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.3'
}
}

Expand Down Expand Up @@ -38,13 +38,19 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'

implementation 'com.google.android.gms:play-services-auth:12.0.1'
api 'com.google.android.gms:play-services-auth:15.0.1'

// Share FluxC version from host project if defined, otherwise fallback to default
if (project.hasProperty("fluxCVersion")) {
implementation "com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:$fluxCVersion"
implementation("com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:$fluxCVersion") {
exclude group: "com.android.support"
exclude group: "org.wordpress", module: "utils"
}
} else {
implementation 'com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:d4e583f21840111065f12e743cbf31de4307266b'
implementation("com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:7c4fa0333cef380aa80b92adbb5e4803b90dd7e5") {
exclude group: "com.android.support"
exclude group: "org.wordpress", module: "utils"
}
}

implementation 'com.github.bumptech.glide:glide:4.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.ContextThemeWrapper;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
Expand All @@ -21,14 +19,26 @@
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;

import javax.inject.Inject;

import static android.app.Activity.RESULT_OK;

public class GoogleFragment extends Fragment implements ConnectionCallbacks, OnConnectionFailedListener {
private static final String STATE_SHOULD_RESOLVE_ERROR = "STATE_SHOULD_RESOLVE_ERROR";
private static final String STATE_FINISHED = "STATE_FINISHED";
private static final String STATE_DISPLAY_NAME = "STATE_DISPLAY_NAME";
private static final String STATE_GOOGLE_EMAIL = "STATE_GOOGLE_EMAIL";
private static final String STATE_GOOGLE_TOKEN_ID = "STATE_GOOGLE_TOKEN_ID";
private static final String STATE_GOOGLE_PHOTO_URL = "STATE_GOOGLE_PHOTO_URL";
private boolean mIsResolvingError;
private boolean mShouldResolveError;
/**
* This flag is used to store the information the finishFlow was called when the fragment wasn't attached to an
* activity (for example an EventBus event was received during ongoing configuration change).
*/
private boolean mFinished;

private static final String STATE_RESOLVING_ERROR = "STATE_RESOLVING_ERROR";
private static final int REQUEST_CONNECT = 1000;
Expand All @@ -52,14 +62,22 @@ public interface GoogleListener {
void onGoogleEmailSelected(String email);
void onGoogleLoginFinished();
void onGoogleSignupFinished(String name, String email, String photoUrl, String username);
void onGoogleSignupError(String msg);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Restore state of error resolving.
mIsResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
mDispatcher.register(this);
if (savedInstanceState != null) {
mIsResolvingError = savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
mShouldResolveError = savedInstanceState.getBoolean(STATE_SHOULD_RESOLVE_ERROR, false);
mFinished = savedInstanceState.getBoolean(STATE_FINISHED, false);
mDisplayName = savedInstanceState.getString(STATE_DISPLAY_NAME);
mGoogleEmail = savedInstanceState.getString(STATE_GOOGLE_EMAIL);
mIdToken = savedInstanceState.getString(STATE_GOOGLE_TOKEN_ID);
mPhotoUrl = savedInstanceState.getString(STATE_GOOGLE_PHOTO_URL);
}

// Configure sign-in to request user's ID, basic profile, email address, and ID token.
// ID and basic profile are included in DEFAULT_SIGN_IN.
Expand All @@ -71,7 +89,7 @@ public void onCreate(Bundle savedInstanceState) {
.build();

// Build Google API client with access to sign-in API and options specified above.
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
Expand All @@ -83,9 +101,15 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, mIsResolvingError);
outState.putBoolean(STATE_SHOULD_RESOLVE_ERROR, mShouldResolveError);
outState.putBoolean(STATE_FINISHED, mFinished);
outState.putString(STATE_DISPLAY_NAME, mDisplayName);
outState.putString(STATE_GOOGLE_EMAIL, mGoogleEmail);
outState.putString(STATE_GOOGLE_TOKEN_ID, mIdToken);
outState.putString(STATE_GOOGLE_PHOTO_URL, mPhotoUrl);
}

@Override
Expand All @@ -98,29 +122,26 @@ public void onAttach(Context context) {
} catch (ClassCastException exception) {
throw new ClassCastException(context.toString() + " must implement GoogleListener");
}

// Show account dialog when Google API onConnected callback returns before fragment is attached.
if (mGoogleApiClient != null && mGoogleApiClient.isConnected() && !mIsResolvingError && !mShouldResolveError) {
showAccountDialog();
if (mFinished) {
finishFlow();
}
}

@Override
public void onDetach() {
super.onDetach();
public void onDestroy() {
disconnectGoogleClient();
AppLog.d(T.MAIN, "GOOGLE SIGNUP/LOGIN: disconnecting google client");
mDispatcher.unregister(this);
super.onDestroy();
}

@Override
public void onStart() {
super.onStart();
mDispatcher.register(this);
}

@Override
public void onStop() {
super.onStop();
mDispatcher.unregister(this);
public void onResume() {
super.onResume();
// Show account dialog when Google API onConnected callback returns before fragment is attached.
if (mGoogleApiClient != null && mGoogleApiClient.isConnected() && !mIsResolvingError && !mShouldResolveError) {
startFlow();
}
}

@Override
Expand All @@ -130,8 +151,9 @@ public void onConnected(Bundle bundle) {
if (mShouldResolveError) {
mShouldResolveError = false;

// if the fragment is not attached to an activity, the process is started in the onResume
if (isAdded()) {
showAccountDialog();
startFlow();
}
}
}
Expand All @@ -154,7 +176,7 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
mIsResolvingError = false;
AppLog.e(AppLog.T.NUX, GoogleApiAvailability.getInstance().getErrorString(
connectionResult.getErrorCode()));
showErrorDialog(getString(R.string.login_error_generic));
showError(getString(R.string.login_error_generic));
}
}
}
Expand All @@ -172,7 +194,7 @@ public void connectGoogleClient() {
mShouldResolveError = true;
mGoogleApiClient.connect();
} else {
showAccountDialog();
startFlow();
}
}

Expand All @@ -183,16 +205,24 @@ protected void disconnectGoogleClient() {
}
}

protected void showAccountDialog() {
protected void startFlow() {
// Do nothing here. This should be overridden by inheriting class.
}

protected void showErrorDialog(String message) {
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme))
.setMessage(message)
.setPositiveButton(R.string.login_error_button, null)
.create();
dialog.show();
protected void finishFlow() {
/* This flag might get lost when the finishFlow is called after the fragment's
onSaveInstanceState was called - however it's a very rare case, since the fragment is retained across
config changes. */
mFinished = true;
if (getActivity() != null) {
AppLog.d(T.MAIN, "GOOGLE SIGNUP/LOGIN: finishing signup/login");
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
}
}

protected void showError(String message) {
finishFlow();
mGoogleListener.onGoogleSignupError(message);
}

@Override
Expand All @@ -208,7 +238,7 @@ public void onActivityResult(int request, int result, Intent data) {
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
} else {
showAccountDialog();
startFlow();
}

mIsResolvingError = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class Login2FaFragment extends LoginBaseFormFragment<LoginListener> imple

private static final String TWO_FACTOR_TYPE_AUTHENTICATOR = "authenticator";
private static final String TWO_FACTOR_TYPE_BACKUP = "backup";
private static final String TWO_FACTOR_TYPE_SMS = "sms";

public static final String TWO_FACTOR_TYPE_SMS = "sms";
public static final String TAG = "login_2fa_fragment_tag";

private static final Pattern TWO_STEP_AUTH_CODE = Pattern.compile("^[0-9]{6}");
Expand Down Expand Up @@ -376,7 +376,7 @@ protected void endProgress() {
private void handleAuthError(AuthenticationErrorType error, String errorMessage) {
switch (error) {
case INVALID_OTP:
show2FaError(errorMessage);
show2FaError(getString(R.string.invalid_verification_code));
break;
case NEEDS_2FA:
// we get this error when requesting a verification code sent via SMS so, just ignore it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public interface LoginAnalyticsListener {
void trackAnalyticsSignIn(AccountStore accountStore, SiteStore siteStore, boolean isWpcomLogin);
void trackCreatedAccount();
void trackCreatedAccount(String username, String email);
void trackEmailFormViewed();
void trackInsertedInvalidUrl();
void trackLoginAccessed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ protected void setupLabel(@NonNull TextView label) {
label.setText(R.string.login_log_in_for_share_intent);
break;
case FULL:
case WPCOM_LOGIN_ONLY:
label.setText(R.string.enter_email_wordpress_com);
break;
case JETPACK_STATS:
label.setText(R.string.stats_sign_in_jetpack_different_com_account);
label.setText(R.string.login_to_to_connect_jetpack);
break;
case WPCOM_REAUTHENTICATE:
label.setText(R.string.auth_required);
Expand Down Expand Up @@ -149,7 +150,7 @@ public void onClick(View view) {
if (isAdded()) {
mOldSitesIDs = SiteUtils.getCurrentSiteIds(mSiteStore, false);
mIsSocialLogin = true;
mLoginListener.addGoogleLoginFragment(LoginEmailFragment.this);
mLoginListener.addGoogleLoginFragment();
} else {
AppLog.e(T.NUX, "Google login could not be started. LoginEmailFragment was not attached.");
showErrorDialog(getString(R.string.login_error_generic_start));
Expand Down Expand Up @@ -177,6 +178,7 @@ public void onClick(View view) {

switch (mLoginListener.getLoginMode()) {
case FULL:
case WPCOM_LOGIN_ONLY:
case SHARE_INTENT:
siteLoginButtonIcon.setImageResource(R.drawable.ic_domains_grey_24dp);
siteLoginButtonText.setText(R.string.enter_site_address_instead);
Expand Down
Loading

0 comments on commit 1042a27

Please sign in to comment.