浏览代码

#2137

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 年之前
父节点
当前提交
e5c8cc39b9

+ 1 - 0
iOSClient/NCGlobal.swift

@@ -229,6 +229,7 @@ class NCGlobal: NSObject {
     @objc let errordMethodNotSupported: Int         = 405
     @objc let errordMethodNotSupported: Int         = 405
     @objc let errorConflict: Int                    = 409
     @objc let errorConflict: Int                    = 409
     @objc let errorPreconditionFailed: Int          = 412
     @objc let errorPreconditionFailed: Int          = 412
+    @objc let errorNCUnauthorized: Int              = 997
     @objc let errorConnectionLost: Int              = -1005
     @objc let errorConnectionLost: Int              = -1005
     @objc let errorNetworkNotAvailable: Int         = -1009
     @objc let errorNetworkNotAvailable: Int         = -1009
     @objc let errorBadServerResponse: Int           = -1011
     @objc let errorBadServerResponse: Int           = -1011

+ 0 - 13
iOSClient/Networking/NCNetworking.swift

@@ -366,11 +366,6 @@ import Photos
             } else {
             } else {
 
 
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: error.errorDescription, sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusDownloadError)
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: error.errorDescription, sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusDownloadError)
-                #if !EXTENSION
-                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)
-                }
-                #endif
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
             }
             }
 
 
@@ -546,14 +541,6 @@ import Photos
                     NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                     NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
 
 
-                } else if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
-
-                    #if !EXTENSION
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)
-                    #endif
-                    NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
-
                 } else {
                 } else {
                     if size == 0 {
                     if size == 0 {
                         errorDescription = "File length 0"
                         errorDescription = "File length 0"

+ 28 - 47
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -23,67 +23,50 @@
 import UIKit
 import UIKit
 import NextcloudKit
 import NextcloudKit
 
 
-@objc class NCNetworkingCheckRemoteUser: NSObject {
-    @objc public static let shared: NCNetworkingCheckRemoteUser = {
-        let instance = NCNetworkingCheckRemoteUser()
-        return instance
-    }()
+class NCNetworkingCheckRemoteUser {
 
 
-    var checkRemoteUserInProgress = false
-
-    @objc func checkRemoteUser(account: String, error: NKError) {
-
-        if self.checkRemoteUserInProgress {
-            return
-        } else {
-            self.checkRemoteUserInProgress = true
-        }
+    func checkRemoteUser(account: String, error: NKError) {
 
 
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
         guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
-            self.checkRemoteUserInProgress = false
             return
             return
         }
         }
 
 
-        if serverVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
-
-            if error.errorCode == NCGlobal.shared.errorUnauthorized {
-
-                let token = CCUtility.getPassword(account)!
-                if token == "" {
-                    self.checkRemoteUserInProgress = false
-                    return
-                }
+        // remove all process ----
 
 
-                NextcloudKit.shared.getRemoteWipeStatus(serverUrl: tableAccount.urlBase, token: token) { account, wipe, error in
+        NCNetworking.shared.cancelAllTransfer(account: account) { }
+        NCOperationQueue.shared.cancelAllQueue()
+        NCNetworking.shared.cancelAllTask()
 
 
-                    let appDelegate = UIApplication.shared.delegate as! AppDelegate
-                    if wipe {
+        // -----------------------
 
 
-                        appDelegate.deleteAccount(account, wipe: true)
-                        let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_wipe_account_")
-                        NCContentPresenter.shared.messageNotification(tableAccount.user, error: error, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, priority: .max)
-                        NextcloudKit.shared.setRemoteWipeCompletition(serverUrl: tableAccount.urlBase, token: token) { _, _ in print("wipe") }
+        if serverVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
 
 
-                    } else {
+            let token = CCUtility.getPassword(account)!
+            if token.isEmpty {
+                return
+            }
 
 
-                        if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() && !CCUtility.getPassword(account).isEmpty && !appDelegate.deletePasswordSession {
-                            let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
-                            let error = NKError(errorCode: error.errorCode, errorDescription: description)
-                            NCContentPresenter.shared.showError(error: error, priority: .max)
-                            CCUtility.setPassword(account, password: nil)
-                            appDelegate.deletePasswordSession = true
-                        }
-                    }
+            NextcloudKit.shared.getRemoteWipeStatus(serverUrl: tableAccount.urlBase, token: token) { account, wipe, error in
 
 
-                    self.checkRemoteUserInProgress = false
-                }
+                let appDelegate = UIApplication.shared.delegate as! AppDelegate
+                if wipe {
 
 
-            } else {
+                    appDelegate.deleteAccount(account, wipe: true)
+                    let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_wipe_account_")
+                    NCContentPresenter.shared.messageNotification(tableAccount.user, error: error, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, priority: .max)
+                    NextcloudKit.shared.setRemoteWipeCompletition(serverUrl: tableAccount.urlBase, token: token) { _, _ in print("wipe") }
 
 
-                NCContentPresenter.shared.showError(error: error, priority: .max)
+                } else {
 
 
-                self.checkRemoteUserInProgress = false
+                    if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() && !CCUtility.getPassword(account).isEmpty && !appDelegate.deletePasswordSession {
+                        let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
+                        let error = NKError(errorCode: error.errorCode, errorDescription: description)
+                        NCContentPresenter.shared.showError(error: error, priority: .max)
+                        CCUtility.setPassword(account, password: nil)
+                        appDelegate.deletePasswordSession = true
+                    }
+                }
             }
             }
 
 
         } else if CCUtility.getPassword(account) != "" {
         } else if CCUtility.getPassword(account) != "" {
@@ -94,8 +77,6 @@ import NextcloudKit
                 NCContentPresenter.shared.showError(error: error, priority: .max)
                 NCContentPresenter.shared.showError(error: error, priority: .max)
                 CCUtility.setPassword(account, password: nil)
                 CCUtility.setPassword(account, password: nil)
             }
             }
-
-            self.checkRemoteUserInProgress = false
         }
         }
     }
     }
 }
 }

+ 1 - 11
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -318,17 +318,7 @@ import Alamofire
 
 
                         } else {
                         } else {
 
 
-                            if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
-
-                                #if !EXTENSION
-                                NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)
-                                #endif
-                                NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: error.errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
-                                
-                            } else {
-
-                                NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: error.errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
-                            }
+                            NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: error.errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
 
 
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
                         }
                         }

+ 2 - 5
iOSClient/Networking/NCService.swift

@@ -103,8 +103,8 @@ class NCService: NSObject {
         NextcloudKit.shared.getUserProfile(queue: NKCommon.shared.backgroundQueue) { account, userProfile, error in
         NextcloudKit.shared.getUserProfile(queue: NKCommon.shared.backgroundQueue) { account, userProfile, error in
             guard error == .success, account == self.appDelegate.account else {
             guard error == .success, account == self.appDelegate.account else {
                 NCBrandColor.shared.settingThemingColor(account: account)
                 NCBrandColor.shared.settingThemingColor(account: account)
-                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, error: error)
+                if error.errorCode == NCGlobal.shared.errorNCUnauthorized || error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
+                    NCNetworkingCheckRemoteUser().checkRemoteUser(account: account, error: error)
                 }
                 }
                 return
                 return
             }
             }
@@ -150,9 +150,6 @@ class NCService: NSObject {
         NextcloudKit.shared.getCapabilities(queue: NKCommon.shared.backgroundQueue) { account, data, error in
         NextcloudKit.shared.getCapabilities(queue: NKCommon.shared.backgroundQueue) { account, data, error in
             guard error == .success, let data = data else {
             guard error == .success, let data = data else {
                 NCBrandColor.shared.settingThemingColor(account: account)
                 NCBrandColor.shared.settingThemingColor(account: account)
-                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, error: error)
-                }
                 return
                 return
             }
             }