mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
taking into account the servers ability to sign out all devices
This commit is contained in:
parent
7a4a6030db
commit
4200b4b5e9
@ -48,7 +48,7 @@ sealed interface OnboardingAction : VectorViewModelAction {
|
||||
data class WebLoginSuccess(val credentials: Credentials) : OnboardingAction
|
||||
data class InitWith(val loginConfig: LoginConfig?) : OnboardingAction
|
||||
data class ResetPassword(val email: String, val newPassword: String?) : OnboardingAction
|
||||
data class ConfirmNewPassword(val newPassword: String) : OnboardingAction
|
||||
data class ConfirmNewPassword(val newPassword: String, val signOutAllDevices: Boolean) : OnboardingAction
|
||||
object ResendResetPassword : OnboardingAction
|
||||
object ResetPasswordMailConfirmed : OnboardingAction
|
||||
|
||||
|
@ -150,7 +150,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||
is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is OnboardingAction.ResetPassword -> handleResetPassword(action)
|
||||
OnboardingAction.ResendResetPassword -> handleResendResetPassword()
|
||||
is OnboardingAction.ConfirmNewPassword -> handleConfirmNewPassword(action)
|
||||
is OnboardingAction.ConfirmNewPassword -> handleResetPasswordConfirmed(action)
|
||||
is OnboardingAction.ResetPasswordMailConfirmed -> handleResetPasswordMailConfirmed()
|
||||
is OnboardingAction.PostRegisterAction -> handleRegisterAction(action.registerAction)
|
||||
is OnboardingAction.ResetAction -> handleResetAction(action)
|
||||
@ -457,10 +457,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||
withState { state ->
|
||||
val resetState = state.resetState
|
||||
when (resetState.email) {
|
||||
null -> {
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("Developer error - No reset email has been set")))
|
||||
}
|
||||
null -> _viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("Developer error - No reset email has been set")))
|
||||
else -> {
|
||||
startResetPasswordFlow(resetState.email) {
|
||||
setState { copy(isLoading = false) }
|
||||
@ -484,9 +481,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleConfirmNewPassword(action: OnboardingAction.ConfirmNewPassword) {
|
||||
setState { copy(resetState = resetState.copy(newPassword = action.newPassword)) }
|
||||
handleResetPasswordMailConfirmed()
|
||||
private fun handleResetPasswordConfirmed(action: OnboardingAction.ConfirmNewPassword) {
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
confirmPasswordReset(action.newPassword, action.signOutAllDevices)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleResetPasswordMailConfirmed() {
|
||||
@ -498,27 +497,24 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("Developer error - No new password has been set")))
|
||||
}
|
||||
else -> {
|
||||
runCatching { loginWizard.resetPasswordMailConfirmed(newPassword) }.fold(
|
||||
onSuccess = {
|
||||
setState {
|
||||
copy(
|
||||
isLoading = false,
|
||||
resetState = ResetState()
|
||||
)
|
||||
}
|
||||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess)
|
||||
},
|
||||
onFailure = {
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
else -> confirmPasswordReset(newPassword, logoutAllDevices = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun confirmPasswordReset(newPassword: String, logoutAllDevices: Boolean) {
|
||||
runCatching { loginWizard.resetPasswordMailConfirmed(newPassword, logoutAllDevices = logoutAllDevices) }.fold(
|
||||
onSuccess = {
|
||||
setState { copy(isLoading = false, resetState = ResetState()) }
|
||||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess)
|
||||
},
|
||||
onFailure = {
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleDirectLogin(action: AuthenticateAction.LoginDirect, homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
|
@ -20,6 +20,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.core.extensions.associateContentStateWith
|
||||
@ -29,6 +30,7 @@ import im.vector.app.core.extensions.isEmail
|
||||
import im.vector.app.core.extensions.setOnImeDoneListener
|
||||
import im.vector.app.databinding.FragmentFtueResetPasswordInputBinding
|
||||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
import im.vector.app.features.onboarding.OnboardingViewState
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.widget.textChanges
|
||||
@ -59,14 +61,22 @@ class FtueAuthResetPasswordEntryFragment : AbstractFtueAuthFragment<FragmentFtue
|
||||
}
|
||||
|
||||
private fun resetPassword() {
|
||||
val password = views.emailEntryInput.content()
|
||||
viewModel.handle(OnboardingAction.ConfirmNewPassword(newPassword = password))
|
||||
viewModel.handle(
|
||||
OnboardingAction.ConfirmNewPassword(
|
||||
newPassword = views.emailEntryInput.content(),
|
||||
signOutAllDevices = views.entrySignOutAll.isChecked
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onError(throwable: Throwable) {
|
||||
views.emailEntryInput.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
|
||||
override fun updateWithState(state: OnboardingViewState) {
|
||||
views.entrySignOutAll.isVisible = state.resetState.supportsLogoutAllDevices
|
||||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
viewModel.handle(OnboardingAction.ResetResetPassword)
|
||||
}
|
||||
|
10
vector/src/main/res/drawable/ic_new_password.xml
Normal file
10
vector/src/main/res/drawable/ic_new_password.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="70dp"
|
||||
android:height="70dp"
|
||||
android:viewportWidth="70"
|
||||
android:viewportHeight="70">
|
||||
<path
|
||||
android:pathData="M30.125,16.213C27.088,16.213 24.625,18.676 24.625,21.713V31.527H21.625C19.968,31.527 18.625,32.87 18.625,34.527V53.125C18.625,54.782 19.968,56.125 21.625,56.125H49.375C51.032,56.125 52.375,54.782 52.375,53.125V34.527C52.375,32.87 51.032,31.527 49.375,31.527H46.375V21.713C46.375,18.676 43.913,16.213 40.875,16.213H30.125ZM43.375,31.527V21.713C43.375,20.333 42.256,19.213 40.875,19.213H30.125C28.744,19.213 27.625,20.333 27.625,21.713V31.527H43.375Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
@ -43,7 +43,7 @@
|
||||
android:background="@drawable/circle"
|
||||
android:backgroundTint="?colorSecondary"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_email"
|
||||
android:src="@drawable/ic_new_password"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntryHeaderTitle"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintHeight_percent="0.12"
|
||||
@ -113,7 +113,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="-14dp"
|
||||
android:buttonTint="@color/checkbox_tint_selector"
|
||||
app:layout_constraintBottom_toTopOf="@id/entrySpacing"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntrySubmit"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
@ -124,22 +124,12 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/ftue_auth_sign_out_all_devices"
|
||||
app:layout_constraintBottom_toTopOf="@id/entrySpacing"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntrySubmit"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@id/entrySignOutAll"
|
||||
app:layout_constraintTop_toBottomOf="@id/emailEntryInput" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/entrySpacing"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntrySubmit"
|
||||
app:layout_constraintHeight_percent="0.03"
|
||||
app:layout_constraintTop_toBottomOf="@id/entrySignOutAll"
|
||||
app:layout_constraintVertical_bias="0"
|
||||
app:layout_constraintVertical_chainStyle="packed" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/emailEntrySubmit"
|
||||
style="@style/Widget.Vector.Button.Login"
|
||||
@ -150,7 +140,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/entrySpacing" />
|
||||
app:layout_constraintTop_toBottomOf="@id/entrySignOutAll" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user