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