adding logout_devices parameter to the password change sdk api, matching reset password
This commit is contained in:
parent
d9fd627bb1
commit
4f09160697
|
@ -73,9 +73,8 @@ interface LoginWizard {
|
|||
* When this method succeed, tha account password will be effectively modified.
|
||||
*
|
||||
* @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.
|
||||
* @param logoutAllDevices defaults to true, all devices will be logged out. False values will only be taken into account
|
||||
* if [org.matrix.android.sdk.api.auth.data.LoginFlowResult.isLogoutDevicesSupported] is true.
|
||||
*/
|
||||
suspend fun resetPasswordMailConfirmed(newPassword: String, logoutAllDevices: Boolean = true)
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
|||
interface AccountService {
|
||||
/**
|
||||
* Ask the homeserver to change the password.
|
||||
*
|
||||
* @param password Current password.
|
||||
* @param newPassword New password
|
||||
* @param logoutAllDevices defaults to true, all devices will be logged out. False values will only be taken into account
|
||||
* if [org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities.canControlLogoutDevices] is true.
|
||||
*/
|
||||
suspend fun changePassword(
|
||||
password: String,
|
||||
newPassword: String
|
||||
)
|
||||
suspend fun changePassword(password: String, newPassword: String, logoutAllDevices: Boolean = true)
|
||||
|
||||
/**
|
||||
* Deactivate the account.
|
||||
|
|
|
@ -29,13 +29,17 @@ internal data class ChangePasswordParams(
|
|||
val auth: UserPasswordAuth? = null,
|
||||
|
||||
@Json(name = "new_password")
|
||||
val newPassword: String? = null
|
||||
val newPassword: String? = null,
|
||||
|
||||
@Json(name = "logout_devices")
|
||||
val logoutDevices: Boolean = true
|
||||
) {
|
||||
companion object {
|
||||
fun create(userId: String, oldPassword: String, newPassword: String): ChangePasswordParams {
|
||||
fun create(userId: String, oldPassword: String, newPassword: String, logoutDevices: Boolean): ChangePasswordParams {
|
||||
return ChangePasswordParams(
|
||||
auth = UserPasswordAuth(user = userId, password = oldPassword),
|
||||
newPassword = newPassword
|
||||
newPassword = newPassword,
|
||||
logoutDevices = logoutDevices
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ import javax.inject.Inject
|
|||
internal interface ChangePasswordTask : Task<ChangePasswordTask.Params, Unit> {
|
||||
data class Params(
|
||||
val password: String,
|
||||
val newPassword: String
|
||||
val newPassword: String,
|
||||
val logoutAllDevices: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,7 @@ internal class DefaultChangePasswordTask @Inject constructor(
|
|||
) : ChangePasswordTask {
|
||||
|
||||
override suspend fun execute(params: ChangePasswordTask.Params) {
|
||||
val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword)
|
||||
val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword, params.logoutAllDevices)
|
||||
try {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
accountAPI.changePassword(changePasswordParams)
|
||||
|
|
|
@ -25,8 +25,8 @@ internal class DefaultAccountService @Inject constructor(
|
|||
private val deactivateAccountTask: DeactivateAccountTask
|
||||
) : AccountService {
|
||||
|
||||
override suspend fun changePassword(password: String, newPassword: String) {
|
||||
changePasswordTask.execute(ChangePasswordTask.Params(password, newPassword))
|
||||
override suspend fun changePassword(password: String, newPassword: String, logoutAllDevices: Boolean) {
|
||||
changePasswordTask.execute(ChangePasswordTask.Params(password, newPassword, logoutAllDevices))
|
||||
}
|
||||
|
||||
override suspend fun deactivateAccount(eraseAllData: Boolean, userInteractiveAuthInterceptor: UserInteractiveAuthInterceptor) {
|
||||
|
|
|
@ -66,6 +66,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
||||
import org.matrix.android.sdk.api.session.getUser
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerConfig
|
||||
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
|
@ -178,9 +179,10 @@ class VectorSettingsGeneralFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities()
|
||||
// Password
|
||||
// Hide the preference if password can not be updated
|
||||
if (session.homeServerCapabilitiesService().getHomeServerCapabilities().canChangePassword) {
|
||||
if (homeServerCapabilities.canChangePassword) {
|
||||
mPasswordPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
onPasswordUpdateClick()
|
||||
false
|
||||
|
|
Loading…
Reference in New Issue