passing the logout devices parameters to the account/password endpoint

This commit is contained in:
Adam Brown 2022-05-30 17:23:24 +01:00
parent c10254dbfa
commit f21e30f7c7
3 changed files with 16 additions and 9 deletions

View File

@ -66,7 +66,7 @@ interface LoginWizard {
* [resetPasswordMailConfirmed] is successfully called.
*
* @param email an email previously associated to the account the user wants the password to be reset.
* @return a [ResetCapabilities] if the reset is successful
* @return a [ResetCapabilities] if the reset is successful.
*/
suspend fun resetPassword(email: String): ResetCapabilities
@ -74,7 +74,10 @@ interface LoginWizard {
* Confirm the new password, once the user has checked their email
* When this method succeed, tha account password will be effectively modified.
*
* @param newPassword the desired new password
* @param newPassword the desired new password.
* @param logoutAllDevices when true, all devices will be logged out. False values will only be taken into account
* if [ResetCapabilities.supportsLogoutAllDevices] is supported.
* When [ResetCapabilities.supportsLogoutAllDevices] is false the default behaviour is to logout all devices.
*/
suspend fun resetPasswordMailConfirmed(newPassword: String)
suspend fun resetPasswordMailConfirmed(newPassword: String, logoutAllDevices: Boolean = true)
}

View File

@ -121,7 +121,6 @@ internal class DefaultLoginWizard(
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(result))
.also { pendingSessionStore.savePendingSessionData(it) }
val versions = executeRequest(null) {
authAPI.versions()
}
@ -129,12 +128,13 @@ internal class DefaultLoginWizard(
return ResetCapabilities(supportsLogoutAllDevices = versions.doesServerSupportLogoutDevices())
}
override suspend fun resetPasswordMailConfirmed(newPassword: String) {
override suspend fun resetPasswordMailConfirmed(newPassword: String, logoutAllDevices: Boolean) {
val resetPasswordData = pendingSessionData.resetPasswordData ?: throw IllegalStateException("Developer error - Must call resetPassword first")
val param = ResetPasswordMailConfirmed.create(
pendingSessionData.clientSecret,
resetPasswordData.addThreePidRegistrationResponse.sid,
newPassword
newPassword,
logoutAllDevices
)
executeRequest(null) {

View File

@ -30,13 +30,17 @@ internal data class ResetPasswordMailConfirmed(
// the new password
@Json(name = "new_password")
val newPassword: String? = null
val newPassword: String? = null,
@Json(name = "logout_devices")
val logoutDevices: Boolean? = null
) {
companion object {
fun create(clientSecret: String, sid: String, newPassword: String): ResetPasswordMailConfirmed {
fun create(clientSecret: String, sid: String, newPassword: String, logoutDevices: Boolean?): ResetPasswordMailConfirmed {
return ResetPasswordMailConfirmed(
auth = AuthParams.createForResetPassword(clientSecret, sid),
newPassword = newPassword
newPassword = newPassword,
logoutDevices = logoutDevices
)
}
}