mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
Login screens: reset password: display a warning when the process is not finished
This commit is contained in:
parent
f87526e615
commit
71ae3c4a8c
4 changed files with 49 additions and 24 deletions
|
@ -80,23 +80,40 @@ abstract class AbstractLoginFragment : VectorBaseFragment(), OnBackPressed {
|
|||
abstract fun onRegistrationError(throwable: Throwable)
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
if (loginViewModel.isPasswordSent) {
|
||||
// Ask for confirmation before cancelling the registration
|
||||
AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.login_signup_cancel_confirmation_title)
|
||||
.setMessage(R.string.login_signup_cancel_confirmation_content)
|
||||
.setPositiveButton(R.string.login_signup_cancel_confirmation_yes) { _, _ ->
|
||||
resetViewModel()
|
||||
vectorBaseActivity.onBackPressed()
|
||||
}
|
||||
.setNegativeButton(R.string.login_signup_cancel_confirmation_no, null)
|
||||
.show()
|
||||
return when {
|
||||
loginViewModel.isRegistrationStarted -> {
|
||||
// Ask for confirmation before cancelling the registration
|
||||
AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.login_signup_cancel_confirmation_title)
|
||||
.setMessage(R.string.login_signup_cancel_confirmation_content)
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
resetViewModel()
|
||||
vectorBaseActivity.onBackPressed()
|
||||
}
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show()
|
||||
|
||||
return true
|
||||
} else {
|
||||
resetViewModel()
|
||||
// Do not consume the Back event
|
||||
return false
|
||||
true
|
||||
}
|
||||
loginViewModel.isResetPasswordStarted -> {
|
||||
// Ask for confirmation before cancelling the reset password
|
||||
AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.login_reset_password_cancel_confirmation_title)
|
||||
.setMessage(R.string.login_reset_password_cancel_confirmation_content)
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
resetViewModel()
|
||||
vectorBaseActivity.onBackPressed()
|
||||
}
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show()
|
||||
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
resetViewModel()
|
||||
// Do not consume the Back event
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
onRegistrationStageNotSupported()
|
||||
} else {
|
||||
// Go on with registration flow
|
||||
if (loginViewModel.isPasswordSent) {
|
||||
if (loginViewModel.isRegistrationStarted) {
|
||||
handleRegistrationNavigation(loginViewEvents.flowResult)
|
||||
} else {
|
||||
// First ask for login and password
|
||||
|
|
|
@ -69,9 +69,14 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
val currentThreePid: String?
|
||||
get() = registrationWizard?.currentThreePid
|
||||
|
||||
var isPasswordSent: Boolean = false
|
||||
// True when login and password are sent with success to the homeserver
|
||||
var isRegistrationStarted: Boolean = false
|
||||
private set
|
||||
|
||||
// True when email is sent with success to the homeserver
|
||||
val isResetPasswordStarted: Boolean
|
||||
get() = resetPasswordEmail.isNullOrBlank().not()
|
||||
|
||||
private var registrationWizard: RegistrationWizard? = null
|
||||
private var loginWizard: LoginWizard? = null
|
||||
|
||||
|
@ -232,7 +237,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
action.initialDeviceName,
|
||||
object : MatrixCallbackDelegate<RegistrationResult>(registrationCallback) {
|
||||
override fun onSuccess(data: RegistrationResult) {
|
||||
isPasswordSent = true
|
||||
isRegistrationStarted = true
|
||||
// Not sure that this will work:
|
||||
// super.onSuccess(data)
|
||||
registrationCallback.onSuccess(data)
|
||||
|
@ -252,7 +257,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
|
||||
when (action) {
|
||||
LoginAction.ResetLogin -> {
|
||||
isPasswordSent = false
|
||||
isRegistrationStarted = false
|
||||
|
||||
setState {
|
||||
copy(
|
||||
|
@ -323,8 +328,6 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
)
|
||||
}
|
||||
} else {
|
||||
resetPasswordEmail = action.email
|
||||
|
||||
setState {
|
||||
copy(
|
||||
asyncResetPassword = Loading()
|
||||
|
@ -333,6 +336,8 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
|
||||
currentTask = safeLoginWizard.resetPassword(action.email, action.newPassword, object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
resetPasswordEmail = action.email
|
||||
|
||||
setState {
|
||||
copy(
|
||||
asyncResetPassword = Success(data)
|
||||
|
@ -370,6 +375,8 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
|
||||
currentTask = safeLoginWizard.resetPasswordMailConfirmed(object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
resetPasswordEmail = null
|
||||
|
||||
setState {
|
||||
copy(
|
||||
asyncResetMailConfirmed = Success(data)
|
||||
|
|
|
@ -84,6 +84,9 @@
|
|||
<string name="login_reset_password_success_notice_2">You have been logged out of all devices and will no longer receive push notifications. To re-enable notifications, sign in again on each device.</string>
|
||||
<string name="login_reset_password_success_submit">Back to Sign In</string>
|
||||
|
||||
<string name="login_reset_password_cancel_confirmation_title">Warning</string>
|
||||
<string name="login_reset_password_cancel_confirmation_content">Your password is not yet changed.\n\nStop the password change process?</string>
|
||||
|
||||
<string name="login_set_email_title">Set email address</string>
|
||||
<string name="login_set_email_notice">Set an email to recover your account. Later, you can optionally allow people you know to discover you by your email.</string>
|
||||
<string name="login_set_email_mandatory_hint">Email</string>
|
||||
|
@ -115,8 +118,6 @@
|
|||
<string name="login_signup_error_user_in_use">That username is taken</string>
|
||||
<string name="login_signup_cancel_confirmation_title">Warning</string>
|
||||
<string name="login_signup_cancel_confirmation_content">Your account is not created yet.\n\nStop the registration process?</string>
|
||||
<string name="login_signup_cancel_confirmation_yes">Yes</string>
|
||||
<string name="login_signup_cancel_confirmation_no">No</string>
|
||||
|
||||
<string name="login_a11y_choose_matrix_org">Select matrix.org</string>
|
||||
<string name="login_a11y_choose_modular">Select modular</string>
|
||||
|
|
Loading…
Reference in a new issue