diff --git a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginModels.swift b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginModels.swift index eef20e50d..6af694b5e 100644 --- a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginModels.swift +++ b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginModels.swift @@ -89,7 +89,6 @@ enum LoginMode { /// Data obtained when calling `LoginWizard.resetPassword` that will be used /// when calling `LoginWizard.checkResetPasswordMailConfirmed`. struct ResetPasswordData { - let newPassword: String let addThreePIDSessionID: String } diff --git a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginParameters.swift b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginParameters.swift index 15ef8e84b..4e4bacb15 100644 --- a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginParameters.swift +++ b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginParameters.swift @@ -100,14 +100,18 @@ struct CheckResetPasswordParameters: DictionaryEncodable { let auth: AuthenticationParameters /// The new password let newPassword: String + /// The sign out of all devices flag + let signoutAllDevices: Bool enum CodingKeys: String, CodingKey { case auth case newPassword = "new_password" + case signoutAllDevices = "logout_devices" } - init(clientSecret: String, sessionID: String, newPassword: String) { + init(clientSecret: String, sessionID: String, newPassword: String, signoutAllDevices: Bool) { self.auth = AuthenticationParameters.resetPasswordParameters(clientSecret: clientSecret, sessionID: sessionID) self.newPassword = newPassword + self.signoutAllDevices = signoutAllDevices } } diff --git a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift index cdc64c70e..1fbd0191b 100644 --- a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift +++ b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift @@ -87,24 +87,26 @@ class LoginWizard { // func loginCustom(data: Codable) async -> MXSession { // // } - + /// Ask the homeserver to reset the user password. The password will not be - /// reset until `checkResetPasswordMailConfirmed` is successfully called. + /// reset until `resetPasswordMailConfirmed` is successfully called. /// - Parameters: /// - email: An email previously associated to the account the user wants the password to be reset. - /// - newPassword: The desired new password - func resetPassword(email: String, newPassword: String) async throws { + func resetPassword(email: String) async throws { let result = try await client.forgetPassword(for: email, clientSecret: state.clientSecret, sendAttempt: state.sendAttempt) state.sendAttempt += 1 - state.resetPasswordData = ResetPasswordData(newPassword: newPassword, addThreePIDSessionID: result) + state.resetPasswordData = ResetPasswordData(addThreePIDSessionID: result) } - + /// Confirm the new password, once the user has checked their email. /// When this method succeeds, the account password will be effectively modified. - func checkResetPasswordMailConfirmed() async throws { + /// - Parameters: + /// - newPassword: The desired new password + /// - signoutAllDevices: The flag to sign out of all devices + func resetPasswordMailConfirmed(newPassword: String, signoutAllDevices: Bool) async throws { guard let resetPasswordData = state.resetPasswordData else { MXLog.error("[LoginWizard] resetPasswordMailConfirmed: Reset password data missing. Call resetPassword first.") throw LoginError.resetPasswordNotStarted @@ -112,7 +114,8 @@ class LoginWizard { let parameters = CheckResetPasswordParameters(clientSecret: state.clientSecret, sessionID: resetPasswordData.addThreePIDSessionID, - newPassword: resetPasswordData.newPassword) + newPassword: newPassword, + signoutAllDevices: signoutAllDevices) try await client.resetPassword(parameters: parameters)