From 54121c99a37f4755e4ac3b0865313c1cd1c78a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 26 Feb 2020 21:27:03 +0100 Subject: [PATCH] [Login/Captcha] Update captcha to fit smaller screens. Fix Librus invalid login error with captcha. --- .../librus/login/LibrusLoginPortal.kt | 14 +++--- .../edziennik/utils/CheckableImageView.java | 6 +++ app/src/main/res/layout/recaptcha_dialog.xml | 48 +++++++++++-------- app/src/main/res/layout/recaptcha_view.xml | 2 +- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/login/LibrusLoginPortal.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/login/LibrusLoginPortal.kt index e8e00950..68fa64ae 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/login/LibrusLoginPortal.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/login/LibrusLoginPortal.kt @@ -144,18 +144,14 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) { .withResponse(response)) return } - if (json.getBoolean("captchaRequired") == true) { - data.error(ApiError(TAG, ERROR_CAPTCHA_LIBRUS_PORTAL) - .withResponse(response) - .withApiResponse(json)) - return - } val error = if (response.code() == 200) null else json.getJsonArray("errors")?.getString(0) error?.let { code -> when { code.contains("Sesja logowania wygasła") -> ERROR_LOGIN_LIBRUS_PORTAL_CSRF_EXPIRED code.contains("Upewnij się, że nie") -> ERROR_LOGIN_LIBRUS_PORTAL_INVALID_LOGIN + // this doesn't work anyway: `errors` is an object with `g-recaptcha-response` set + code.contains("robotem") -> ERROR_CAPTCHA_LIBRUS_PORTAL else -> ERROR_LOGIN_LIBRUS_PORTAL_ACTION_ERROR }.let { errorCode -> data.error(ApiError(TAG, errorCode) @@ -164,6 +160,12 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) { return } } + if (json.getBoolean("captchaRequired") == true) { + data.error(ApiError(TAG, ERROR_CAPTCHA_LIBRUS_PORTAL) + .withResponse(response) + .withApiResponse(json)) + return + } authorize(json.getString("redirect", LIBRUS_AUTHORIZE_URL)) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/CheckableImageView.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/CheckableImageView.java index 8765c7e1..593c7b10 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/CheckableImageView.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/CheckableImageView.java @@ -46,6 +46,12 @@ public class CheckableImageView extends AppCompatImageView implements Checkable return drawableState; } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); + } + @Override public void toggle() { setChecked(!checked); } diff --git a/app/src/main/res/layout/recaptcha_dialog.xml b/app/src/main/res/layout/recaptcha_dialog.xml index 221883f7..f5465ff5 100644 --- a/app/src/main/res/layout/recaptcha_dialog.xml +++ b/app/src/main/res/layout/recaptcha_dialog.xml @@ -7,7 +7,7 @@ xmlns:tools="http://schemas.android.com/tools"> @@ -39,30 +39,32 @@ @@ -75,7 +77,8 @@ @@ -88,7 +91,8 @@ @@ -100,14 +104,15 @@ android:background="?colorSurface" /> @@ -120,7 +125,8 @@ @@ -133,7 +139,8 @@ @@ -145,14 +152,15 @@ android:background="?colorSurface" /> @@ -165,7 +173,8 @@ @@ -178,7 +187,8 @@ diff --git a/app/src/main/res/layout/recaptcha_view.xml b/app/src/main/res/layout/recaptcha_view.xml index 86cc71db..dba7824b 100644 --- a/app/src/main/res/layout/recaptcha_view.xml +++ b/app/src/main/res/layout/recaptcha_view.xml @@ -13,7 +13,7 @@ android:paddingRight="16dp" android:paddingBottom="8dp">