Update reset password api

This commit is contained in:
ismailgulek
2022-06-01 18:59:08 +03:00
parent 1fa47287a0
commit 0255518f2a
3 changed files with 16 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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
}
}

View File

@@ -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)