12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import Foundation
- import NCCommunication
- @objc class NCNetworkingCheckRemoteUser: NSObject {
- @objc public static let shared: NCNetworkingCheckRemoteUser = {
- let instance = NCNetworkingCheckRemoteUser()
- return instance
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- var checkRemoteUserInProgress = false
- @objc func checkRemoteUser(account: String) {
-
- if self.checkRemoteUserInProgress {
- return;
- } else {
- self.checkRemoteUserInProgress = true;
- }
-
- let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
- guard let tableAccount = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return }
-
- if serverVersionMajor >= k_nextcloud_version_17_0 {
-
- guard let token = CCUtility.getPassword(account) else { return }
-
- NCCommunication.shared.getRemoteWipeStatus(serverUrl: tableAccount.url, token: token) { (account, wipe, errorCode, errorDescriptiuon) in
-
- if wipe {
-
- self.appDelegate.deleteAccount(account, wipe: true)
- NCContentPresenter.shared.messageNotification(tableAccount.user, description: "_wipe_account_", delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
- NCCommunication.shared.setRemoteWipeCompletition(serverUrl: tableAccount.url, token: token) { (account, errorCode, errorDescription) in
- print("wipe");
- }
-
- } else {
-
- if UIApplication.shared.applicationState == .active && NCCommunication.shared.isNetworkReachable() {
- let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.url)
- NCContentPresenter.shared.messageNotification("_error_", description: description, delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: errorCode)
- CCUtility.setPassword(account, password: nil)
- }
- }
- }
-
- } else if CCUtility.getPassword(account) != nil {
-
- if UIApplication.shared.applicationState == .active && NCCommunication.shared.isNetworkReachable() {
- let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.url)
- NCContentPresenter.shared.messageNotification("_error_", description: description, delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: 403)
- CCUtility.setPassword(account, password: nil)
- }
- }
- }
- }
|