mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
moving the reset password new password to the reset confirmation step
- the new password is moved to the in memory view model state
This commit is contained in:
parent
35163f77ba
commit
cc8f17b786
9 changed files with 40 additions and 42 deletions
|
@ -65,18 +65,14 @@ interface LoginWizard {
|
||||||
* [resetPasswordMailConfirmed] is successfully called.
|
* [resetPasswordMailConfirmed] is successfully called.
|
||||||
*
|
*
|
||||||
* @param email an email previously associated to the account the user wants the password to be reset.
|
* @param email an email previously associated to the account the user wants the password to be reset.
|
||||||
* @param newPassword the desired new password, can be optionally set here or as part of [resetPasswordMailConfirmed]
|
|
||||||
*/
|
*/
|
||||||
suspend fun resetPassword(
|
suspend fun resetPassword(email: String)
|
||||||
email: String,
|
|
||||||
newPassword: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirm the new password, once the user has checked their email
|
* Confirm the new password, once the user has checked their email
|
||||||
* When this method succeed, tha account password will be effectively modified.
|
* When this method succeed, tha account password will be effectively modified.
|
||||||
*
|
*
|
||||||
* @param newPassword the desired new password, required if a password was not supplied to [resetPassword]
|
* @param newPassword the desired new password
|
||||||
*/
|
*/
|
||||||
suspend fun resetPasswordMailConfirmed(newPassword: String? = null)
|
suspend fun resetPasswordMailConfirmed(newPassword: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ internal class DefaultLoginWizard(
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetPassword(email: String, newPassword: String?) {
|
override suspend fun resetPassword(email: String) {
|
||||||
val param = RegisterAddThreePidTask.Params(
|
val param = RegisterAddThreePidTask.Params(
|
||||||
RegisterThreePid.Email(email),
|
RegisterThreePid.Email(email),
|
||||||
pendingSessionData.clientSecret,
|
pendingSessionData.clientSecret,
|
||||||
|
@ -118,18 +118,17 @@ internal class DefaultLoginWizard(
|
||||||
authAPI.resetPassword(AddThreePidRegistrationParams.from(param))
|
authAPI.resetPassword(AddThreePidRegistrationParams.from(param))
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(newPassword, result))
|
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(result))
|
||||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetPasswordMailConfirmed(newPassword: String?) {
|
override suspend fun resetPasswordMailConfirmed(newPassword: String) {
|
||||||
val param = pendingSessionData.readResetPasswordDataOrThrow(newPassword).let { (response, password) ->
|
val resetPasswordData = pendingSessionData.resetPasswordData ?: throw IllegalStateException("Developer error - Must call resetPassword first")
|
||||||
ResetPasswordMailConfirmed.create(
|
val param = ResetPasswordMailConfirmed.create(
|
||||||
pendingSessionData.clientSecret,
|
pendingSessionData.clientSecret,
|
||||||
response.sid,
|
resetPasswordData.addThreePidRegistrationResponse.sid,
|
||||||
password
|
newPassword
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
executeRequest(null) {
|
executeRequest(null) {
|
||||||
authAPI.resetPasswordMailConfirmed(param)
|
authAPI.resetPasswordMailConfirmed(param)
|
||||||
|
@ -138,14 +137,4 @@ internal class DefaultLoginWizard(
|
||||||
// Set to null?
|
// Set to null?
|
||||||
// resetPasswordData = null
|
// resetPasswordData = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PendingSessionData.readResetPasswordDataOrThrow(newPassword: String?): Pair<AddThreePidRegistrationResponse, String> {
|
|
||||||
return when (resetPasswordData) {
|
|
||||||
null -> throw IllegalStateException("developer error, no reset password in progress")
|
|
||||||
else -> {
|
|
||||||
val password = newPassword ?: resetPasswordData.newPassword ?: throw IllegalStateException("developer error, no new password set")
|
|
||||||
resetPasswordData.addThreePidRegistrationResponse to password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,5 @@ import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistration
|
||||||
*/
|
*/
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
internal data class ResetPasswordData(
|
internal data class ResetPasswordData(
|
||||||
val newPassword: String?,
|
|
||||||
val addThreePidRegistrationResponse: AddThreePidRegistrationResponse
|
val addThreePidRegistrationResponse: AddThreePidRegistrationResponse
|
||||||
)
|
)
|
||||||
|
|
|
@ -413,7 +413,8 @@ class LoginViewModel @AssistedInject constructor(
|
||||||
copy(
|
copy(
|
||||||
asyncResetPassword = Uninitialized,
|
asyncResetPassword = Uninitialized,
|
||||||
asyncResetMailConfirmed = Uninitialized,
|
asyncResetMailConfirmed = Uninitialized,
|
||||||
resetPasswordEmail = null
|
resetPasswordEmail = null,
|
||||||
|
resetPasswordNewPassword = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,7 +489,7 @@ class LoginViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPassword(action.email, action.newPassword)
|
safeLoginWizard.resetPassword(action.email)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
@ -501,7 +502,8 @@ class LoginViewModel @AssistedInject constructor(
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
asyncResetPassword = Success(Unit),
|
asyncResetPassword = Success(Unit),
|
||||||
resetPasswordEmail = action.email
|
resetPasswordEmail = action.email,
|
||||||
|
resetPasswordNewPassword = action.newPassword
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,7 +532,8 @@ class LoginViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPasswordMailConfirmed()
|
val state = awaitState()
|
||||||
|
safeLoginWizard.resetPasswordMailConfirmed(state.resetPasswordNewPassword!!)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
@ -542,7 +545,8 @@ class LoginViewModel @AssistedInject constructor(
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
asyncResetMailConfirmed = Success(Unit),
|
asyncResetMailConfirmed = Success(Unit),
|
||||||
resetPasswordEmail = null
|
resetPasswordEmail = null,
|
||||||
|
resetPasswordNewPassword = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ data class LoginViewState(
|
||||||
@PersistState
|
@PersistState
|
||||||
val resetPasswordEmail: String? = null,
|
val resetPasswordEmail: String? = null,
|
||||||
@PersistState
|
@PersistState
|
||||||
|
val resetPasswordNewPassword: String? = null,
|
||||||
|
@PersistState
|
||||||
val homeServerUrlFromUser: String? = null,
|
val homeServerUrlFromUser: String? = null,
|
||||||
|
|
||||||
// Can be modified after a Wellknown request
|
// Can be modified after a Wellknown request
|
||||||
|
|
|
@ -392,7 +392,8 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
LoginAction2.ResetResetPassword -> {
|
LoginAction2.ResetResetPassword -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
resetPasswordEmail = null
|
resetPasswordEmail = null,
|
||||||
|
resetPasswordNewPassword = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,7 +444,7 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPassword(action.email, action.newPassword)
|
safeLoginWizard.resetPassword(action.email)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(LoginViewEvents2.Failure(failure))
|
_viewEvents.post(LoginViewEvents2.Failure(failure))
|
||||||
setState { copy(isLoading = false) }
|
setState { copy(isLoading = false) }
|
||||||
|
@ -453,7 +454,8 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
resetPasswordEmail = action.email
|
resetPasswordEmail = action.email,
|
||||||
|
resetPasswordNewPassword = action.newPassword
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +474,8 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPasswordMailConfirmed()
|
val state = awaitState()
|
||||||
|
safeLoginWizard.resetPasswordMailConfirmed(state.resetPasswordNewPassword!!)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
_viewEvents.post(LoginViewEvents2.Failure(failure))
|
_viewEvents.post(LoginViewEvents2.Failure(failure))
|
||||||
setState { copy(isLoading = false) }
|
setState { copy(isLoading = false) }
|
||||||
|
@ -481,7 +484,8 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
resetPasswordEmail = null
|
resetPasswordEmail = null,
|
||||||
|
resetPasswordNewPassword = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ data class LoginViewState2(
|
||||||
@PersistState
|
@PersistState
|
||||||
val resetPasswordEmail: String? = null,
|
val resetPasswordEmail: String? = null,
|
||||||
@PersistState
|
@PersistState
|
||||||
|
val resetPasswordNewPassword: String? = null,
|
||||||
|
@PersistState
|
||||||
val homeServerUrlFromUser: String? = null,
|
val homeServerUrlFromUser: String? = null,
|
||||||
|
|
||||||
// Can be modified after a Wellknown request
|
// Can be modified after a Wellknown request
|
||||||
|
|
|
@ -456,7 +456,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPassword(action.email, action.newPassword)
|
safeLoginWizard.resetPassword(action.email)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
setState { copy(isLoading = false) }
|
setState { copy(isLoading = false) }
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(failure))
|
_viewEvents.post(OnboardingViewEvents.Failure(failure))
|
||||||
|
@ -466,7 +466,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
resetState = ResetState(email = action.email)
|
resetState = ResetState(email = action.email, newPassword = action.newPassword)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,7 +486,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
safeLoginWizard.resetPasswordMailConfirmed()
|
val state = awaitState()
|
||||||
|
safeLoginWizard.resetPasswordMailConfirmed(state.resetState.newPassword!!)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
setState { copy(isLoading = false) }
|
setState { copy(isLoading = false) }
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(failure))
|
_viewEvents.post(OnboardingViewEvents.Failure(failure))
|
||||||
|
|
|
@ -86,7 +86,8 @@ data class PersonalizationState(
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class ResetState(
|
data class ResetState(
|
||||||
val email: String? = null
|
val email: String? = null,
|
||||||
|
val newPassword: String? = null,
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
|
Loading…
Reference in a new issue