From d595578e2b9d1d595b5dd3fe13e30ecb7fa031e5 Mon Sep 17 00:00:00 2001 From: Sergey Eremin Date: Thu, 19 Jan 2017 02:47:15 +0300 Subject: [PATCH] Issue #23 2-Step Verification message/workaround added --- app/build.gradle | 2 +- .../yalpstore/CredentialsDialogBuilder.java | 63 +++++++++++++++---- app/src/main/res/values-ru/strings.xml | 6 +- app/src/main/res/values/strings.xml | 6 +- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b31d337de..d29afdb12 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,5 +24,5 @@ android { } dependencies { - compile 'com.github.yeriomin:play-store-api:cfd47603fa' + compile 'com.github.yeriomin:play-store-api:053e98ceae' } diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/CredentialsDialogBuilder.java b/app/src/main/java/com/github/yeriomin/yalpstore/CredentialsDialogBuilder.java index a569f4f98..c85fc9a0b 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/CredentialsDialogBuilder.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/CredentialsDialogBuilder.java @@ -1,8 +1,12 @@ package com.github.yeriomin.yalpstore; +import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.util.Log; @@ -18,6 +22,8 @@ import java.io.IOException; public class CredentialsDialogBuilder { + static private final String APP_PASSWORDS_URL = "https://security.google.com/settings/security/apppasswords"; + private Context context; protected GoogleApiAsyncTask taskClone; @@ -56,7 +62,7 @@ public class CredentialsDialogBuilder { final String email = editEmail.getText().toString(); final String password = editPassword.getText().toString(); if (email.isEmpty() || password.isEmpty()) { - Toast.makeText(c, c.getString(R.string.error_credentials_empty), Toast.LENGTH_LONG).show(); + toast(c, R.string.error_credentials_empty); return; } @@ -71,6 +77,14 @@ public class CredentialsDialogBuilder { return ad; } + static private void toast(Context c, int stringId, String... stringArgs) { + Toast.makeText( + c.getApplicationContext(), + c.getString(stringId, stringArgs), + Toast.LENGTH_LONG + ).show(); + } + private class CheckCredentialsTask extends AsyncTask { private Dialog dialog; @@ -126,17 +140,14 @@ public class CredentialsDialogBuilder { if (e instanceof CredentialsEmptyException) { Log.w(getClass().getName(), "Credentials empty"); } else if (e instanceof AuthException) { - Toast.makeText( - c.getApplicationContext(), - c.getString(R.string.error_incorrect_password), - Toast.LENGTH_LONG - ).show(); + if (null != ((AuthException) e).getTwoFactorUrl()) { + this.dialog.dismiss(); + getTwoFactorAuthDialog().show(); + } else { + toast(c, R.string.error_incorrect_password); + } } else if (e instanceof IOException) { - Toast.makeText( - c.getApplicationContext(), - c.getString(R.string.error_network_other, e.getMessage()), - Toast.LENGTH_LONG - ).show(); + toast(c, R.string.error_network_other, e.getMessage()); } else { Log.w(getClass().getName(), "Unknown exception " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); @@ -146,5 +157,35 @@ public class CredentialsDialogBuilder { this.taskClone.execute(); } } + + private AlertDialog getTwoFactorAuthDialog() { + final Context context = this.dialog.getContext(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + return builder + .setMessage(R.string.dialog_message_two_factor) + .setTitle(R.string.dialog_title_two_factor) + .setPositiveButton( + R.string.dialog_two_factor_create_password, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(APP_PASSWORDS_URL)); + context.startActivity(i); + System.exit(0); + } + } + ) + .setNegativeButton( + R.string.dialog_two_factor_cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + System.exit(0); + } + } + ) + .create(); + } } } diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a73aa8774..26a4752ef 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -4,6 +4,10 @@ %s ↓, %.1f★, %s Обновлений нет Ничего не найдено + Позднее + Создать пароль + Двухэтапная аутентификация + Похоже, в вашем аккаунте включена двухэтапная аутентификация.\n\nПожалуйста, создайте пароль приложения для Yalp Store и используйте его для входа.\n\nНажмите \"Создать пароль\" для перехода на страницу создания паролей приложений. Разлогиниться? Вы уверены что хотите разлогиниться? Получаем отзывы @@ -50,7 +54,7 @@ e-mail пароль Вход в аккаунт Google - Для работы приложения требуетются данные для доступа к аккаунту Google.\r\nИмейте в виду, что это приложение нарушает договор использования Play Store. Так что безопаснее использовать любой одноразовый Google аккаунт, под которым вы хотя бы раз залогинились в Play Store. + Для работы приложения требуетются данные для доступа к аккаунту Google.\n\nИмейте в виду, что это приложение нарушает договор использования Play Store. Так что безопаснее использовать любой одноразовый Google аккаунт, под которым вы хотя бы раз залогинились в Play Store. Обновления Поиск: "%s" Готово. Коснитесь чтобы установить. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d39eb594d..19fcb83ec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,10 @@ Ignore updates Unignore updates Search applications + Not now + Create password + 2-Step Verification + It appears you have enabled 2-Step Verification for your account.\n\nPlease, create a dedicated app password for Yalp Store and use it to log in to the Yalp Store.\n\nTap \"Create password\" to be redirected to password creation page. Log out? Are you sure you want to log out? Getting reviews @@ -50,7 +54,7 @@ e-mail here password here Google account access - Google account email and password are required for this app to function.\nKeep in mind that using this app violates Play Store ToS. It would probably be safer to use a throwaway Google account which has logged in to Play Store at least once and has accepted Play Store ToS. + Google account email and password are required for this app to function.\n\nKeep in mind that using this app violates Play Store ToS. It would probably be safer to use a throwaway Google account which has logged in to Play Store at least once and has accepted Play Store ToS. Updates Searching: "%s" Download complete. Touch to install.