Issue #23 2-Step Verification message/workaround added

This commit is contained in:
Sergey Eremin
2017-01-19 02:47:15 +03:00
parent 20b8fee0fc
commit d595578e2b
4 changed files with 63 additions and 14 deletions

View File

@@ -24,5 +24,5 @@ android {
}
dependencies {
compile 'com.github.yeriomin:play-store-api:cfd47603fa'
compile 'com.github.yeriomin:play-store-api:053e98ceae'
}

View File

@@ -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<String, Void, Throwable> {
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();
}
}
}

View File

@@ -4,6 +4,10 @@
<string name="list_line_2_search" formatted="false">%s ↓, %.1f★, %s</string>
<string name="list_empty_updates">Обновлений нет</string>
<string name="list_empty_search">Ничего не найдено</string>
<string name="dialog_two_factor_cancel">Позднее</string>
<string name="dialog_two_factor_create_password">Создать пароль</string>
<string name="dialog_title_two_factor">Двухэтапная аутентификация</string>
<string name="dialog_message_two_factor">Похоже, в вашем аккаунте включена двухэтапная аутентификация.\n\nПожалуйста, создайте пароль приложения для Yalp Store и используйте его для входа.\n\nНажмите \"Создать пароль\" для перехода на страницу создания паролей приложений.</string>
<string name="dialog_title_logout">Разлогиниться?</string>
<string name="dialog_message_logout">Вы уверены что хотите разлогиниться?</string>
<string name="dialog_title_reviews">Получаем отзывы</string>
@@ -50,7 +54,7 @@
<string name="credentials_hint_email">e-mail</string>
<string name="credentials_hint_password">пароль</string>
<string name="credentials_title">Вход в аккаунт Google</string>
<string name="credentials_message">Для работы приложения требуетются данные для доступа к аккаунту Google.\r\nИмейте в виду, что это приложение нарушает договор использования Play Store. Так что безопаснее использовать любой одноразовый Google аккаунт, под которым вы хотя бы раз залогинились в Play Store.</string>
<string name="credentials_message">Для работы приложения требуетются данные для доступа к аккаунту Google.\n\nИмейте в виду, что это приложение нарушает договор использования Play Store. Так что безопаснее использовать любой одноразовый Google аккаунт, под которым вы хотя бы раз залогинились в Play Store.</string>
<string name="activity_title_updates">Обновления</string>
<string name="activity_title_search" formatted="false">Поиск: "%s"</string>
<string name="notification_download_complete">Готово. Коснитесь чтобы установить.</string>

View File

@@ -11,6 +11,10 @@
<string name="action_ignore">Ignore updates</string>
<string name="action_unignore">Unignore updates</string>
<string name="search_title">Search applications</string>
<string name="dialog_two_factor_cancel">Not now</string>
<string name="dialog_two_factor_create_password">Create password</string>
<string name="dialog_title_two_factor">2-Step Verification</string>
<string name="dialog_message_two_factor">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.</string>
<string name="dialog_title_logout">Log out?</string>
<string name="dialog_message_logout">Are you sure you want to log out?</string>
<string name="dialog_title_reviews">Getting reviews</string>
@@ -50,7 +54,7 @@
<string name="credentials_hint_email">e-mail here</string>
<string name="credentials_hint_password">password here</string>
<string name="credentials_title">Google account access</string>
<string name="credentials_message">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.</string>
<string name="credentials_message">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.</string>
<string name="activity_title_updates">Updates</string>
<string name="activity_title_search" formatted="false">Searching: "%s"</string>
<string name="notification_download_complete">Download complete. Touch to install.</string>