ios_app_v2/yobble/ViewModels/ChangePasswordViewModel.swift
2025-10-07 01:51:15 +03:00

35 lines
1.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
import Combine
final class ChangePasswordViewModel: ObservableObject {
@Published private(set) var isLoading: Bool = false
@Published var successMessage: String?
@Published var errorMessage: String?
private let authService: AuthService
init(authService: AuthService = AuthService()) {
self.authService = authService
}
func changePassword(oldPassword: String, newPassword: String) {
guard !isLoading else { return }
isLoading = true
successMessage = nil
errorMessage = nil
authService.changePassword(oldPassword: oldPassword, newPassword: newPassword) { [weak self] success, message in
guard let self else { return }
DispatchQueue.main.async {
self.isLoading = false
if success {
self.successMessage = message ?? NSLocalizedString("Пароль успешно обновлен.", comment: "")
} else {
self.errorMessage = message ?? NSLocalizedString("Не удалось обновить пароль.", comment: "")
}
}
}
}
}