allow passing the new password when resetting passwords either upfront or as part of the confirmation step
This commit is contained in:
parent
e3d46cfd15
commit
35163f77ba
1
changelog.d/6169.sdk
Normal file
1
changelog.d/6169.sdk
Normal file
@ -0,0 +1 @@
|
|||||||
|
Allows new passwords to be passed at the point of confirmation when resetting a password
|
@ -65,16 +65,18 @@ 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
|
* @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
|
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]
|
||||||
*/
|
*/
|
||||||
suspend fun resetPasswordMailConfirmed()
|
suspend fun resetPasswordMailConfirmed(newPassword: String? = null)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import org.matrix.android.sdk.internal.auth.data.ThreePidMedium
|
|||||||
import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
|
import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
|
||||||
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
||||||
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
|
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
|
||||||
|
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationResponse
|
||||||
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
|
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
import org.matrix.android.sdk.internal.session.content.DefaultContentUrlResolver
|
import org.matrix.android.sdk.internal.session.content.DefaultContentUrlResolver
|
||||||
@ -103,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, newPassword: String?) {
|
||||||
val param = RegisterAddThreePidTask.Params(
|
val param = RegisterAddThreePidTask.Params(
|
||||||
RegisterThreePid.Email(email),
|
RegisterThreePid.Email(email),
|
||||||
pendingSessionData.clientSecret,
|
pendingSessionData.clientSecret,
|
||||||
@ -121,15 +122,14 @@ internal class DefaultLoginWizard(
|
|||||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetPasswordMailConfirmed() {
|
override suspend fun resetPasswordMailConfirmed(newPassword: String?) {
|
||||||
val safeResetPasswordData = pendingSessionData.resetPasswordData
|
val param = pendingSessionData.readResetPasswordDataOrThrow(newPassword).let { (response, password) ->
|
||||||
?: throw IllegalStateException("developer error, no reset password in progress")
|
ResetPasswordMailConfirmed.create(
|
||||||
|
pendingSessionData.clientSecret,
|
||||||
val param = ResetPasswordMailConfirmed.create(
|
response.sid,
|
||||||
pendingSessionData.clientSecret,
|
password
|
||||||
safeResetPasswordData.addThreePidRegistrationResponse.sid,
|
)
|
||||||
safeResetPasswordData.newPassword
|
}
|
||||||
)
|
|
||||||
|
|
||||||
executeRequest(null) {
|
executeRequest(null) {
|
||||||
authAPI.resetPasswordMailConfirmed(param)
|
authAPI.resetPasswordMailConfirmed(param)
|
||||||
@ -138,4 +138,14 @@ 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,6 @@ 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 newPassword: String?,
|
||||||
val addThreePidRegistrationResponse: AddThreePidRegistrationResponse
|
val addThreePidRegistrationResponse: AddThreePidRegistrationResponse
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user