Login screens: reset password: display a better popup when link is not clicked yet
This commit is contained in:
parent
71ae3c4a8c
commit
9fa131c297
|
@ -79,10 +79,12 @@ If the user confirms before the link is clicked, we get an error:
|
||||||
|
|
||||||
401
|
401
|
||||||
|
|
||||||
|
```json
|
||||||
{
|
{
|
||||||
"errcode": "M_UNAUTHORIZED",
|
"errcode": "M_UNAUTHORIZED",
|
||||||
"error": ""
|
"error": ""
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### User clicks on the link
|
### User clicks on the link
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.riotx.core.error
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.failure.Failure
|
||||||
|
import im.vector.matrix.android.api.failure.MatrixError
|
||||||
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
|
fun Throwable.is401(): Boolean {
|
||||||
|
return (this is Failure.ServerError && this.httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
||||||
|
&& this.error.code == MatrixError.UNAUTHORIZED)
|
||||||
|
}
|
|
@ -30,16 +30,15 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
import im.vector.matrix.android.api.auth.registration.RegisterThreePid
|
import im.vector.matrix.android.api.auth.registration.RegisterThreePid
|
||||||
import im.vector.matrix.android.api.failure.Failure
|
import im.vector.matrix.android.api.failure.Failure
|
||||||
import im.vector.matrix.android.api.failure.MatrixError
|
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.error.ErrorFormatter
|
import im.vector.riotx.core.error.ErrorFormatter
|
||||||
|
import im.vector.riotx.core.error.is401
|
||||||
import im.vector.riotx.core.extensions.hideKeyboard
|
import im.vector.riotx.core.extensions.hideKeyboard
|
||||||
import im.vector.riotx.core.extensions.isEmail
|
import im.vector.riotx.core.extensions.isEmail
|
||||||
import im.vector.riotx.core.extensions.setTextOrHide
|
import im.vector.riotx.core.extensions.setTextOrHide
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import kotlinx.android.synthetic.main.fragment_login_generic_text_input_form.*
|
import kotlinx.android.synthetic.main.fragment_login_generic_text_input_form.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.net.ssl.HttpsURLConnection
|
|
||||||
|
|
||||||
enum class TextInputFormFragmentMode {
|
enum class TextInputFormFragmentMode {
|
||||||
SetEmail,
|
SetEmail,
|
||||||
|
@ -242,11 +241,6 @@ class LoginGenericTextInputFormFragment @Inject constructor(private val errorFor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Throwable.is401(): Boolean {
|
|
||||||
return (this is Failure.ServerError && this.httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
|
||||||
&& this.error.code == MatrixError.UNAUTHORIZED)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resetViewModel() {
|
override fun resetViewModel() {
|
||||||
loginViewModel.handle(LoginAction.ResetLogin)
|
loginViewModel.handle(LoginAction.ResetLogin)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.airbnb.mvrx.Success
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.error.ErrorFormatter
|
import im.vector.riotx.core.error.ErrorFormatter
|
||||||
|
import im.vector.riotx.core.error.is401
|
||||||
import kotlinx.android.synthetic.main.fragment_login_reset_password_mail_confirmation.*
|
import kotlinx.android.synthetic.main.fragment_login_reset_password_mail_confirmation.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -64,9 +65,15 @@ class LoginResetPasswordMailConfirmationFragment @Inject constructor(
|
||||||
when (state.asyncResetMailConfirmed) {
|
when (state.asyncResetMailConfirmed) {
|
||||||
is Fail -> {
|
is Fail -> {
|
||||||
// Link in email not yet clicked ?
|
// Link in email not yet clicked ?
|
||||||
|
val message = if (state.asyncResetMailConfirmed.error.is401()) {
|
||||||
|
getString(R.string.auth_reset_password_error_unauthorized)
|
||||||
|
} else {
|
||||||
|
errorFormatter.toHumanReadable(state.asyncResetMailConfirmed.error)
|
||||||
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(requireActivity())
|
AlertDialog.Builder(requireActivity())
|
||||||
.setTitle(R.string.dialog_title_error)
|
.setTitle(R.string.dialog_title_error)
|
||||||
.setMessage(errorFormatter.toHumanReadable(state.asyncResetMailConfirmed.error))
|
.setMessage(message)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,12 @@ import android.os.Parcelable
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.airbnb.mvrx.args
|
import com.airbnb.mvrx.args
|
||||||
import im.vector.matrix.android.api.failure.Failure
|
|
||||||
import im.vector.matrix.android.api.failure.MatrixError
|
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.error.ErrorFormatter
|
import im.vector.riotx.core.error.ErrorFormatter
|
||||||
|
import im.vector.riotx.core.error.is401
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import kotlinx.android.synthetic.main.fragment_login_wait_for_email.*
|
import kotlinx.android.synthetic.main.fragment_login_wait_for_email.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.net.ssl.HttpsURLConnection
|
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class LoginWaitForEmailFragmentArgument(
|
data class LoginWaitForEmailFragmentArgument(
|
||||||
|
@ -79,11 +77,6 @@ class LoginWaitForEmailFragment @Inject constructor(private val errorFormatter:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Throwable.is401(): Boolean {
|
|
||||||
return (this is Failure.ServerError && this.httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
|
||||||
&& this.error.code == MatrixError.UNAUTHORIZED)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resetViewModel() {
|
override fun resetViewModel() {
|
||||||
loginViewModel.handle(LoginAction.ResetLogin)
|
loginViewModel.handle(LoginAction.ResetLogin)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue