Show M_WEAK_PASSWORD error in the password field

This commit is contained in:
Benoit Marty 2020-09-03 15:21:21 +02:00
parent 05ec5bde93
commit 8aada10f0d
2 changed files with 12 additions and 4 deletions

View file

@ -132,6 +132,8 @@ data class MatrixError(
const val M_CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"
/** (Not documented yet) */
const val M_WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION"
/** (Not documented yet) */
const val M_WEAK_PASSWORD = "M_WEAK_PASSWORD"
const val M_TERMS_NOT_SIGNED = "M_TERMS_NOT_SIGNED"

View file

@ -33,13 +33,13 @@ import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.showPassword
import im.vector.app.core.extensions.toReducedUrl
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 io.reactivex.Observable
import io.reactivex.functions.BiFunction
import io.reactivex.rxkotlin.subscribeBy
import kotlinx.android.synthetic.main.fragment_login.*
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 javax.inject.Inject
/**
@ -234,7 +234,13 @@ class LoginFragment @Inject constructor() : AbstractLoginFragment() {
}
override fun onError(throwable: Throwable) {
loginFieldTil.error = errorFormatter.toHumanReadable(throwable)
// Show M_WEAK_PASSWORD error in the password field
if (throwable is Failure.ServerError
&& throwable.error.code == MatrixError.M_WEAK_PASSWORD) {
passwordFieldTil.error = errorFormatter.toHumanReadable(throwable)
} else {
loginFieldTil.error = errorFormatter.toHumanReadable(throwable)
}
}
override fun updateWithState(state: LoginViewState) {