mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
adding a password entry confirmation page for the reset password flow
This commit is contained in:
parent
9abf6e37d1
commit
7a4a6030db
8 changed files with 291 additions and 22 deletions
|
@ -48,6 +48,8 @@ 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
|
||||
object ResendResetPassword : OnboardingAction
|
||||
object ResetPasswordMailConfirmed : OnboardingAction
|
||||
|
||||
data class MaybeUpdateHomeserverFromMatrixId(val userId: String) : OnboardingAction
|
||||
|
|
|
@ -49,6 +49,7 @@ sealed class OnboardingViewEvents : VectorViewEvents {
|
|||
object OnForgetPasswordClicked : OnboardingViewEvents()
|
||||
data class OnResetPasswordSendThreePidDone(val email: String) : OnboardingViewEvents()
|
||||
object OnResetPasswordMailConfirmationSuccess : OnboardingViewEvents()
|
||||
object OnResetPasswordBreakerConfirmed : OnboardingViewEvents()
|
||||
object OnResetPasswordMailConfirmationSuccessDone : OnboardingViewEvents()
|
||||
|
||||
data class OnSendEmailSuccess(val email: String) : OnboardingViewEvents()
|
||||
|
|
|
@ -149,6 +149,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is OnboardingAction.LoginWithToken -> handleLoginWithToken(action)
|
||||
is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is OnboardingAction.ResetPassword -> handleResetPassword(action)
|
||||
OnboardingAction.ResendResetPassword -> handleResendResetPassword()
|
||||
is OnboardingAction.ConfirmNewPassword -> handleConfirmNewPassword(action)
|
||||
is OnboardingAction.ResetPasswordMailConfirmed -> handleResetPasswordMailConfirmed()
|
||||
is OnboardingAction.PostRegisterAction -> handleRegisterAction(action.registerAction)
|
||||
is OnboardingAction.ResetAction -> handleResetAction(action)
|
||||
|
@ -439,25 +441,9 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun handleResetPassword(action: OnboardingAction.ResetPassword) {
|
||||
val safeLoginWizard = loginWizard
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
runCatching { safeLoginWizard.resetPassword(action.email) }.fold(
|
||||
onSuccess = {
|
||||
val state = awaitState()
|
||||
setState {
|
||||
copy(
|
||||
isLoading = false,
|
||||
resetState = createResetState(action, state.selectedHomeserver)
|
||||
)
|
||||
}
|
||||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordSendThreePidDone(action.email))
|
||||
},
|
||||
onFailure = {
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
||||
}
|
||||
)
|
||||
startResetPasswordFlow(action.email) {
|
||||
setState { copy(isLoading = false, resetState = createResetState(action, selectedHomeserver)) }
|
||||
_viewEvents.post(OnboardingViewEvents.OnResetPasswordSendThreePidDone(action.email))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -467,6 +453,42 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
supportsLogoutAllDevices = selectedHomeserverState.isLogoutDevicesSupported
|
||||
)
|
||||
|
||||
private fun handleResendResetPassword() {
|
||||
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")))
|
||||
}
|
||||
else -> {
|
||||
startResetPasswordFlow(resetState.email) {
|
||||
setState { copy(isLoading = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startResetPasswordFlow(email: String, onSuccess: suspend () -> Unit) {
|
||||
val safeLoginWizard = loginWizard
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
runCatching { safeLoginWizard.resetPassword(email) }.fold(
|
||||
onSuccess = { onSuccess.invoke() },
|
||||
onFailure = {
|
||||
setState { copy(isLoading = false) }
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleConfirmNewPassword(action: OnboardingAction.ConfirmNewPassword) {
|
||||
setState { copy(resetState = resetState.copy(newPassword = action.newPassword)) }
|
||||
handleResetPasswordMailConfirmed()
|
||||
}
|
||||
|
||||
private fun handleResetPasswordMailConfirmed() {
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
|
|
|
@ -27,7 +27,7 @@ import im.vector.app.R
|
|||
import im.vector.app.core.utils.colorTerminatingFullStop
|
||||
import im.vector.app.databinding.FragmentFtueResetPasswordBreakerBinding
|
||||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
import im.vector.app.features.onboarding.RegisterAction
|
||||
import im.vector.app.features.onboarding.OnboardingViewEvents
|
||||
import im.vector.app.features.themes.ThemeProvider
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
@ -63,8 +63,9 @@ class FtueAuthResetPasswordBreakerFragment : AbstractFtueAuthFragment<FragmentFt
|
|||
views.emailVerificationTitle.text = getString(R.string.ftue_auth_reset_password_breaker_title)
|
||||
.colorTerminatingFullStop(ThemeUtils.getColor(requireContext(), R.attr.colorSecondary))
|
||||
views.emailVerificationSubtitle.text = getString(R.string.ftue_auth_email_verification_subtitle, params.email)
|
||||
views.emailVerificationResendEmail.debouncedClicks {
|
||||
viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.SendAgainThreePid))
|
||||
views.emailVerificationResendEmail.debouncedClicks { viewModel.handle(OnboardingAction.ResendResetPassword) }
|
||||
views.emailVerificationFooter.debouncedClicks {
|
||||
viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnResetPasswordBreakerConfirmed))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2022 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.app.features.onboarding.ftueauth
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.core.extensions.associateContentStateWith
|
||||
import im.vector.app.core.extensions.content
|
||||
import im.vector.app.core.extensions.editText
|
||||
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 kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.widget.textChanges
|
||||
|
||||
@AndroidEntryPoint
|
||||
class FtueAuthResetPasswordEntryFragment : AbstractFtueAuthFragment<FragmentFtueResetPasswordInputBinding>() {
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueResetPasswordInputBinding {
|
||||
return FragmentFtueResetPasswordInputBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupViews()
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
views.emailEntryInput.associateContentStateWith(button = views.emailEntrySubmit)
|
||||
views.emailEntryInput.setOnImeDoneListener { resetPassword() }
|
||||
views.emailEntrySubmit.debouncedClicks { resetPassword() }
|
||||
|
||||
views.emailEntryInput.editText().textChanges()
|
||||
.onEach {
|
||||
views.emailEntryInput.error = null
|
||||
views.emailEntrySubmit.isEnabled = it.isEmail()
|
||||
}
|
||||
.launchIn(viewLifecycleOwner.lifecycleScope)
|
||||
}
|
||||
|
||||
private fun resetPassword() {
|
||||
val password = views.emailEntryInput.content()
|
||||
viewModel.handle(OnboardingAction.ConfirmNewPassword(newPassword = password))
|
||||
}
|
||||
|
||||
override fun onError(throwable: Throwable) {
|
||||
views.emailEntryInput.error = errorFormatter.toHumanReadable(throwable)
|
||||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
viewModel.handle(OnboardingAction.ResetResetPassword)
|
||||
}
|
||||
}
|
|
@ -190,6 +190,14 @@ class FtueAuthVariant(
|
|||
)
|
||||
}
|
||||
}
|
||||
OnboardingViewEvents.OnResetPasswordBreakerConfirmed -> {
|
||||
supportFragmentManager.popBackStack(FRAGMENT_LOGIN_TAG, POP_BACK_STACK_EXCLUSIVE)
|
||||
activity.addFragmentToBackstack(
|
||||
views.loginFragmentContainer,
|
||||
FtueAuthResetPasswordEntryFragment::class.java,
|
||||
option = commonOption
|
||||
)
|
||||
}
|
||||
is OnboardingViewEvents.OnResetPasswordMailConfirmationSuccess -> {
|
||||
supportFragmentManager.popBackStack(FRAGMENT_LOGIN_TAG, POP_BACK_STACK_EXCLUSIVE)
|
||||
activity.addFragmentToBackstack(
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/LoginFormScrollView"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:colorBackground"
|
||||
android:fillViewport="true"
|
||||
android:paddingTop="0dp"
|
||||
android:paddingBottom="0dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/emailEntryGutterStart"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_start_percent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/emailEntryGutterEnd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="@dimen/ftue_auth_gutter_end_percent" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/headerSpacing"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntryHeaderIcon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0"
|
||||
app:layout_constraintVertical_chainStyle="packed" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/emailEntryHeaderIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/circle"
|
||||
android:backgroundTint="?colorSecondary"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_email"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntryHeaderTitle"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintHeight_percent="0.12"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/headerSpacing"
|
||||
app:tint="@color/palette_white" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emailEntryHeaderTitle"
|
||||
style="@style/Widget.Vector.TextView.Title.Medium"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/ftue_auth_new_password_title"
|
||||
android:textColor="?vctr_content_primary"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntryHeaderSubtitle"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/emailEntryHeaderIcon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emailEntryHeaderSubtitle"
|
||||
style="@style/Widget.Vector.TextView.Subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/ftue_auth_new_password_subtitle"
|
||||
android:textColor="?vctr_content_secondary"
|
||||
app:layout_constraintBottom_toTopOf="@id/titleContentSpacing"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/emailEntryHeaderTitle" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/titleContentSpacing"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/emailEntryInput"
|
||||
app:layout_constraintHeight_percent="0.03"
|
||||
app:layout_constraintTop_toBottomOf="@id/emailEntryHeaderSubtitle" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/emailEntryInput"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/ftue_auth_new_password_entry_title"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@id/entrySignOutAll"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/titleContentSpacing">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textEmailAddress"
|
||||
android:maxLines="1" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox
|
||||
android:id="@+id/entrySignOutAll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="-14dp"
|
||||
android:buttonTint="@color/checkbox_tint_selector"
|
||||
app:layout_constraintBottom_toTopOf="@id/entrySpacing"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/emailEntryInput" />
|
||||
|
||||
<TextView
|
||||
style="@style/Widget.Vector.TextView.Subtitle"
|
||||
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_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"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/ftue_auth_reset_password"
|
||||
android:textAllCaps="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/emailEntryGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/emailEntryGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/entrySpacing" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
|
@ -38,6 +38,11 @@
|
|||
<string name="ftue_auth_email_entry_title">Email Address</string>
|
||||
<string name="ftue_auth_reset_password_email_subtitle">We will send you a verification link.</string>
|
||||
<string name="ftue_auth_reset_password_breaker_title">Check your email.</string>
|
||||
<string name="ftue_auth_new_password_entry_title">New Password</string>
|
||||
<string name="ftue_auth_new_password_title">Choose a new password</string>
|
||||
<string name="ftue_auth_new_password_subtitle">Make sure it\'s 8 characters or more.</string>
|
||||
<string name="ftue_auth_reset_password">Reset password</string>
|
||||
<string name="ftue_auth_sign_out_all_devices">Sign out all devices</string>
|
||||
|
||||
<string name="ftue_auth_email_verification_title">Check your email to verify.</string>
|
||||
<!-- Note for translators, %s is the users email address -->
|
||||
|
|
Loading…
Add table
Reference in a new issue