From 025d3daf904fd3bf2ab0937fd06e0fd4b9c175a7 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 22 Nov 2022 15:20:25 +0600 Subject: [PATCH 1/3] 5948-Retry_on_401_for_murena_account issue:https://gitlab.e.foundation/e/backlog/-/issues/5948 murena accounts can be e.email/murena.io. Users sometime make mistake & try to login with wrong accountID. For example, accountId is abc@e.email but user is putting abc@murena.io; vice-versa. In this case, when 401 occurs, we want to try again with another accountId in background, for better UX. --- .../ui/setup/DetectConfigurationFragment.kt | 23 +++++++--- .../ui/setup/EeloAuthenticatorFragment.kt | 46 +++++++++++++++++++ .../davdroid/ui/setup/LoginActivity.kt | 2 + 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt index 6fb02a7ce..f9c802bff 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt @@ -50,15 +50,24 @@ class DetectConfigurationFragment: Fragment() { // remove "Detecting configuration" fragment, it shouldn't come back parentFragmentManager.popBackStack() - if (result.calDAV != null || result.cardDAV != null) + if (result.calDAV != null || result.cardDAV != null) { + requireActivity().intent.putExtra(LoginActivity.RETRY_ON_401, false) + parentFragmentManager.beginTransaction() - .replace(android.R.id.content, AccountDetailsFragment()) - .addToBackStack(null) - .commit() - else + .replace(android.R.id.content, AccountDetailsFragment()) + .addToBackStack(null) + .commit() + } else if(requireActivity().intent.getBooleanExtra(LoginActivity.RETRY_ON_401, false) && loginModel.configuration?.encountered401 == true) { + // murena account has encounters 401, most-probably user put wrong accountId (ex: abc@murena.io instead of abc@e.email) + // do nothing, EeloAuthenticatorFragment will retry with another time with another user email + return@observe + } else { + requireActivity().intent.putExtra(LoginActivity.RETRY_ON_401, false) + parentFragmentManager.beginTransaction() - .add(NothingDetectedFragment(), null) - .commit() + .add(NothingDetectedFragment(), null) + .commit() + } }) } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt index 626a28085..4aa41e600 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt @@ -16,6 +16,7 @@ package at.bitfire.davdroid.ui.setup +import android.annotation.SuppressLint import android.content.Context import android.net.ConnectivityManager import android.os.Bundle @@ -101,6 +102,42 @@ class EeloAuthenticatorFragment : Fragment() { } } + override fun onResume() { + super.onResume() + + if (requireActivity().intent.getBooleanExtra(LoginActivity.RETRY_ON_401, false) && switchUserName()) { + // user wants to login with murena account, but most probably provided wrong accountId as email. + // switching email is done, retry login + login() + requireActivity().intent.putExtra(LoginActivity.RETRY_ON_401, false) // disable retry option to mitigate infinite looping + } + } + + /*** + * user put wrong accountId for the first time (for ex: abc@murena.io instead of abc@e.email) + * this method check provided email & switch to alternative email if possible so retry can be handled in bg + * @return email field's value is successfully switched or not. If true, proceed to retry + */ + @SuppressLint("SetTextI18n") + private fun switchUserName(): Boolean { + if (urlpwd_user_name.text.toString().contains("@")) { + val username = urlpwd_user_name.text.toString().substringBefore("@") + val dns = urlpwd_user_name.text.toString().substringAfter("@") + + if (dns == Constants.E_SYNC_URL) { + urlpwd_user_name.setText(username + "@" + Constants.EELO_SYNC_HOST) + return true + } + + if (dns == Constants.EELO_SYNC_HOST) { + urlpwd_user_name.setText(username + "@" + Constants.E_SYNC_URL) + return true + } + } + + return false + } + override fun onSaveInstanceState(outState: Bundle) { outState.putBoolean(TOGGLE_BUTTON_CHECKED_KEY, toggleButtonState) super.onSaveInstanceState(outState) @@ -136,6 +173,14 @@ class EeloAuthenticatorFragment : Fragment() { } + // if user wants to login with murena account, add support to automated retry + // if user in any case provide wrong accountId as email (ex: abc@murena.io instead of abc@e.email) + private fun addSupportRetryOn401IfPossible(serverUrl: String) { + if ("https://${Constants.EELO_SYNC_HOST}" == serverUrl) { + requireActivity().intent.putExtra(LoginActivity.RETRY_ON_401, true) + } + } + private fun validate(): Boolean { var valid = false @@ -143,6 +188,7 @@ class EeloAuthenticatorFragment : Fragment() { if (serverUrl.isEmpty()) { serverUrl = computeDomain(requireView().urlpwd_user_name.text.toString()) + addSupportRetryOn401IfPossible(serverUrl) } fun validateUrl() { diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginActivity.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginActivity.kt index 971ad07b1..f289bbe2a 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginActivity.kt @@ -51,6 +51,8 @@ class LoginActivity: AppCompatActivity() { const val OPEN_APP_PACKAGE_AFTER_AUTH = "open_app_package_after_auth" const val OPEN_APP_ACTIVITY_AFTER_AUTH = "open_app_activity_after_auth" + + const val RETRY_ON_401 = "retry_on_401" } @Inject -- GitLab From 2e76fa93957abf0346366fd9788ffc7a930cd14f Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 22 Nov 2022 15:53:52 +0600 Subject: [PATCH 2/3] Set default domain for murena account to https://murena.io issue:https://gitlab.e.foundation/e/backlog/-/issues/5948 --- .../at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt index 4aa41e600..cfd3cbeab 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt @@ -144,7 +144,8 @@ class EeloAuthenticatorFragment : Fragment() { } private fun computeDomain(username: CharSequence?) : String { - var domain = "" + var domain = "https://${Constants.EELO_SYNC_HOST}" + if (!username.isNullOrEmpty() && username.toString().contains("@")) { var dns = username.toString().substringAfter("@") if (dns == Constants.E_SYNC_URL) { -- GitLab From f18888c932835f090fdaa6dfa04fa6d96267e257 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 22 Nov 2022 18:21:36 +0600 Subject: [PATCH 3/3] update murena account login title & email field text issue: https://gitlab.e.foundation/e/backlog/-/issues/5948 --- app/src/main/res/layout/fragment_eelo_authenticator.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/fragment_eelo_authenticator.xml b/app/src/main/res/layout/fragment_eelo_authenticator.xml index 7be63935b..d55e69a6c 100644 --- a/app/src/main/res/layout/fragment_eelo_authenticator.xml +++ b/app/src/main/res/layout/fragment_eelo_authenticator.xml @@ -76,7 +76,7 @@ android:id="@+id/urlpwd_user_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/login_email_address" + android:hint="@string/login_user_id" android:inputType="textEmailAddress" android:textColor="@color/primaryTextColor" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 868b971c8..18ff3c134 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -271,8 +271,9 @@ Add account - Use your e.email or murena.io ID to sign in: + Use your Murena ID (@e.email or @murena.io) to sign in: Login with email address + User ID Email address Valid email address required Password -- GitLab