mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 19:10:49 +02:00
MESSENGER-4951 Changed password confirmation
This commit is contained in:
@@ -68,6 +68,8 @@ enum ChangePasswordViewAction {
|
||||
}
|
||||
|
||||
enum ChangePasswordErrorType: Hashable {
|
||||
/// The password has been changed on the server
|
||||
case passwordChangeSucceeded
|
||||
/// An error response from the homeserver.
|
||||
case mxError(String)
|
||||
/// User entered new passwords do not match
|
||||
|
||||
@@ -49,19 +49,25 @@ class ChangePasswordViewModel: ChangePasswordViewModelType, ChangePasswordViewMo
|
||||
switch viewAction {
|
||||
case .submit:
|
||||
guard state.bindings.newPassword1 == state.bindings.newPassword2 else {
|
||||
Task { await displayError(.passwordsDontMatch) }
|
||||
Task { await displayError(.passwordsDontMatch, primaryButtonCallback: {}) }
|
||||
return
|
||||
}
|
||||
Task { await callback?(.submit(oldPassword: state.bindings.oldPassword,
|
||||
newPassword: state.bindings.newPassword1,
|
||||
signoutAllDevices: state.bindings.signoutAllDevices)) }
|
||||
signoutAllDevices: state.bindings.signoutAllDevices))
|
||||
}
|
||||
case .toggleSignoutAllDevices:
|
||||
state.bindings.signoutAllDevices.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor func displayError(_ type: ChangePasswordErrorType) {
|
||||
@MainActor func displayError(_ type: ChangePasswordErrorType, primaryButtonCallback: @escaping (() -> Void)) {
|
||||
switch type {
|
||||
case .passwordChangeSucceeded:
|
||||
state.bindings.alertInfo = AlertInfo(id: .passwordChangeSucceeded,
|
||||
title: BWIL10n.settingsPasswordChanged,
|
||||
message: "",
|
||||
primaryButton: (VectorL10n.ok, action: { primaryButtonCallback() }))
|
||||
case .mxError(let message):
|
||||
state.bindings.alertInfo = AlertInfo(id: type,
|
||||
title: VectorL10n.error,
|
||||
|
||||
@@ -21,5 +21,5 @@ protocol ChangePasswordViewModelProtocol {
|
||||
var context: ChangePasswordViewModelType.Context { get }
|
||||
|
||||
/// Display an error to the user.
|
||||
@MainActor func displayError(_ type: ChangePasswordErrorType)
|
||||
@MainActor func displayError(_ type: ChangePasswordErrorType, primaryButtonCallback: @escaping (() -> Void))
|
||||
}
|
||||
|
||||
+18
-6
@@ -110,13 +110,18 @@ final class ChangePasswordCoordinator: Coordinator, Presentable {
|
||||
|
||||
currentTask = Task { [weak self] in
|
||||
do {
|
||||
try passwordValidator.validate(password: newPassword)
|
||||
try await parameters.restClient.changePassword(from: oldPassword, to: newPassword, logoutDevices: signoutAllDevices)
|
||||
try self?.passwordValidator.validate(password: newPassword)
|
||||
try await self?.parameters.restClient.changePassword(from: oldPassword, to: newPassword, logoutDevices: signoutAllDevices)
|
||||
|
||||
guard !Task.isCancelled else { return }
|
||||
|
||||
self?.stopLoading()
|
||||
self?.callback?()
|
||||
|
||||
if BWIBuildSettings.shared.showPasswordChangedConfirmation {
|
||||
self?.handleSuccess()
|
||||
} else {
|
||||
self?.callback?()
|
||||
}
|
||||
} catch {
|
||||
self?.stopLoading()
|
||||
self?.handleError(error)
|
||||
@@ -128,14 +133,21 @@ final class ChangePasswordCoordinator: Coordinator, Presentable {
|
||||
@MainActor private func handleError(_ error: Error) {
|
||||
if let mxError = MXError(nsError: error as NSError) {
|
||||
let message = mxError.authenticationErrorMessage()
|
||||
changePasswordViewModel.displayError(.mxError(message))
|
||||
changePasswordViewModel.displayError(.mxError(message), primaryButtonCallback: {})
|
||||
return
|
||||
}
|
||||
|
||||
if let error = error as? PasswordValidatorError {
|
||||
changePasswordViewModel.displayError(.mxError(error.localizedDescription))
|
||||
changePasswordViewModel.displayError(.mxError(error.localizedDescription), primaryButtonCallback: {})
|
||||
} else {
|
||||
changePasswordViewModel.displayError(.unknown)
|
||||
changePasswordViewModel.displayError(.unknown, primaryButtonCallback: {})
|
||||
}
|
||||
}
|
||||
|
||||
// bwi: 4951 - password changed confirmation
|
||||
@MainActor private func handleSuccess() {
|
||||
changePasswordViewModel.displayError(.passwordChangeSucceeded, primaryButtonCallback: { [weak self] in
|
||||
self?.callback?()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user