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 6fb02a7ceb7c5fe096f961a0cc396828a277e34b..f9c802bffeaa6248adab469330e3cd15523a2e68 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 626a2808534a0ba339458eb2929554e44f895dc4..cfd3cbeabdf73a08ace5e52e0ff51d20f83f0dce 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,13 +102,50 @@ 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)
}
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) {
@@ -136,6 +174,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 +189,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 971ad07b119eb99f34e879801080fdb03210b886..f289bbe2a8af000359e4214a1abeb0cca475e04f 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
diff --git a/app/src/main/res/layout/fragment_eelo_authenticator.xml b/app/src/main/res/layout/fragment_eelo_authenticator.xml
index 7be63935bec2090f5b9aa9f92840fb0c0090622d..d55e69a6c21334f9852d762964bdd6418f4085e0 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 868b971c8a577ae2f43b1f72455304a19ab33a73..18ff3c13420387c668e7590b21faca1ee11e0b0c 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