moving the not accepting registration error handling to the login fragment
This commit is contained in:
parent
11cc284bcc
commit
373385b29f
|
@ -64,6 +64,11 @@ fun Throwable.isInvalidPassword(): Boolean {
|
|||
error.message == "Invalid password"
|
||||
}
|
||||
|
||||
fun Throwable.isRegistrationDisabled(): Boolean {
|
||||
return this is Failure.ServerError && error.code == MatrixError.M_FORBIDDEN &&
|
||||
httpCode == HttpsURLConnection.HTTP_FORBIDDEN
|
||||
}
|
||||
|
||||
fun Throwable.isInvalidUIAAuth(): Boolean {
|
||||
return this is Failure.ServerError &&
|
||||
error.code == MatrixError.M_FORBIDDEN &&
|
||||
|
|
|
@ -34,8 +34,6 @@ import im.vector.app.features.onboarding.OnboardingViewModel
|
|||
import im.vector.app.features.onboarding.OnboardingViewState
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.MatrixError
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
/**
|
||||
* Parent Fragment for all the login/registration screens
|
||||
|
@ -85,21 +83,8 @@ abstract class AbstractFtueAuthFragment<VB : ViewBinding> : VectorBaseFragment<V
|
|||
is CancellationException ->
|
||||
/* Ignore this error, user has cancelled the action */
|
||||
Unit
|
||||
is Failure.ServerError ->
|
||||
if (throwable.error.code == MatrixError.M_FORBIDDEN &&
|
||||
throwable.httpCode == HttpsURLConnection.HTTP_FORBIDDEN /* 403 */) {
|
||||
MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(R.string.dialog_title_error)
|
||||
.setMessage(getString(R.string.login_registration_disabled))
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
} else {
|
||||
onError(throwable)
|
||||
}
|
||||
is Failure.UnrecognizedCertificateFailure ->
|
||||
showUnrecognizedCertificateFailure(throwable)
|
||||
else ->
|
||||
onError(throwable)
|
||||
is Failure.UnrecognizedCertificateFailure -> showUnrecognizedCertificateFailure(throwable)
|
||||
else -> onError(throwable)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.autofill.HintConstants
|
|||
import androidx.core.text.isDigitsOnly
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.hideKeyboard
|
||||
import im.vector.app.core.extensions.hidePassword
|
||||
|
@ -46,6 +47,7 @@ import kotlinx.coroutines.flow.onEach
|
|||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.MatrixError
|
||||
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
||||
import org.matrix.android.sdk.api.failure.isRegistrationDisabled
|
||||
import reactivecircus.flowbinding.android.widget.textChanges
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -254,12 +256,39 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment<
|
|||
}
|
||||
|
||||
override fun onError(throwable: Throwable) {
|
||||
// Show M_WEAK_PASSWORD error in the password field
|
||||
if (throwable is Failure.ServerError &&
|
||||
throwable.error.code == MatrixError.M_WEAK_PASSWORD) {
|
||||
// Trick to display the error without text.
|
||||
views.loginFieldTil.error = " "
|
||||
when {
|
||||
throwable is Failure.ServerError &&
|
||||
throwable.error.code == MatrixError.M_FORBIDDEN &&
|
||||
throwable.error.message.isEmpty() -> {
|
||||
// Login with email, but email unknown
|
||||
views.loginFieldTil.error = getString(R.string.login_login_with_email_error)
|
||||
}
|
||||
|
||||
throwable is Failure.ServerError && throwable.error.code == MatrixError.M_WEAK_PASSWORD -> {
|
||||
views.passwordFieldTil.error = errorFormatter.toHumanReadable(throwable)
|
||||
} else {
|
||||
views.loginFieldTil.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
|
||||
throwable.isInvalidPassword() && spaceInPassword() -> {
|
||||
views.passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password)
|
||||
}
|
||||
|
||||
throwable.isInvalidPassword() -> {
|
||||
views.passwordFieldTil.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
|
||||
throwable.isRegistrationDisabled() -> {
|
||||
MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(R.string.dialog_title_error)
|
||||
.setMessage(getString(R.string.login_registration_disabled))
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
else -> {
|
||||
super.onError(throwable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,23 +307,6 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment<
|
|||
}
|
||||
}
|
||||
|
||||
override fun showFailure(throwable: Throwable) {
|
||||
if (throwable is Failure.ServerError &&
|
||||
throwable.error.code == MatrixError.M_FORBIDDEN &&
|
||||
throwable.error.message.isEmpty()) {
|
||||
// Login with email, but email unknown
|
||||
views.loginFieldTil.error = getString(R.string.login_login_with_email_error)
|
||||
} else {
|
||||
// Trick to display the error without text.
|
||||
views.loginFieldTil.error = " "
|
||||
if (throwable.isInvalidPassword() && spaceInPassword()) {
|
||||
views.passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password)
|
||||
} else {
|
||||
views.passwordFieldTil.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if password ends or starts with spaces
|
||||
*/
|
||||
|
|
|
@ -54,7 +54,7 @@ class FtueAuthResetPasswordFragment @Inject constructor() : AbstractFtueAuthFrag
|
|||
setupSubmitButton()
|
||||
}
|
||||
|
||||
override fun showFailure(throwable: Throwable) {
|
||||
override fun onError(throwable: Throwable) {
|
||||
views.resetPasswordEmailTil.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class FtueAuthResetPasswordMailConfirmationFragment @Inject constructor() : Abst
|
|||
setupUi(state)
|
||||
}
|
||||
|
||||
override fun showFailure(throwable: Throwable) {
|
||||
override fun onError(throwable: Throwable) {
|
||||
// Link in email not yet clicked ?
|
||||
val message = if (throwable.is401()) {
|
||||
getString(R.string.auth_reset_password_error_unauthorized)
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
package im.vector.app.features.onboarding
|
||||
|
||||
import android.net.Uri
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import com.airbnb.mvrx.test.MvRxTestRule
|
||||
import im.vector.app.features.login.ReAuthHelper
|
||||
import im.vector.app.features.login.SignMode
|
||||
|
|
Loading…
Reference in New Issue