mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-18 07:28:28 +02:00
Update reset password api
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user