Pārlūkot izejas kodu

Improved checkRemoteUser

marinofaggiana 3 gadi atpakaļ
vecāks
revīzija
6804425972

+ 2 - 2
iOSClient/Networking/NCNetworking.swift

@@ -373,7 +373,7 @@ import Queuer
                 
                 #if !EXTENSION
                 if errorCode == 401 || errorCode == 403 {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode)
+                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode, errorDescription: errorDescription)
                 } 
                 #endif
             }
@@ -601,7 +601,7 @@ import Queuer
                 } else if errorCode == 401 || errorCode == 403 {
                     
                     #if !EXTENSION
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode)
+                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode, errorDescription: errorDescription)
                     #endif
                     
                     NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)

+ 25 - 18
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -32,7 +32,7 @@ import NCCommunication
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var checkRemoteUserInProgress = false
 
-    @objc func checkRemoteUser(account: String, errorCode: Int) {
+    @objc func checkRemoteUser(account: String, errorCode: Int, errorDescription: String) {
            
         if self.checkRemoteUserInProgress {
             return
@@ -45,28 +45,35 @@ import NCCommunication
         
         if serverVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
             
-            let token = CCUtility.getPassword(account)!
-            if token == "" { return }
-            
-            NCCommunication.shared.getRemoteWipeStatus(serverUrl: tableAccount.urlBase, token: token) { (account, wipe, errorCode, errorDescriptiuon) in
+            if errorCode == 401 {
+                
+                let token = CCUtility.getPassword(account)!
+                if token == "" { return }
                 
-                if wipe {
+                NCCommunication.shared.getRemoteWipeStatus(serverUrl: tableAccount.urlBase, token: token) { (account, wipe, errorCode, errorDescriptiuon) in
                     
-                    self.appDelegate.deleteAccount(account, wipe: true)
-                    NCContentPresenter.shared.messageNotification(tableAccount.user, description: "_wipe_account_", delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
-                    NCCommunication.shared.setRemoteWipeCompletition(serverUrl: tableAccount.urlBase, token: token) { (account, errorCode, errorDescription) in
-                        print("wipe")
+                    if wipe {
+                        
+                        self.appDelegate.deleteAccount(account, wipe: true)
+                        NCContentPresenter.shared.messageNotification(tableAccount.user, description: "_wipe_account_", delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
+                        NCCommunication.shared.setRemoteWipeCompletition(serverUrl: tableAccount.urlBase, 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.urlBase)
+                            NCContentPresenter.shared.messageNotification("_error_", description: description, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            CCUtility.setPassword(account, password: nil)
+                        }
                     }
                     
-                } else {
-                    
-                    if UIApplication.shared.applicationState == .active &&  NCCommunication.shared.isNetworkReachable() {
-                        let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
-                        NCContentPresenter.shared.messageNotification("_error_", description: description, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                        CCUtility.setPassword(account, password: nil)
-                    }
+                    self.checkRemoteUserInProgress = false
                 }
                 
+            } else {
+                
+                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                
                 self.checkRemoteUserInProgress = false
             }
             
@@ -74,7 +81,7 @@ import NCCommunication
                
             if UIApplication.shared.applicationState == .active &&  NCCommunication.shared.isNetworkReachable() {
                 let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
-                NCContentPresenter.shared.messageNotification("_error_", description: description, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: 403)
+                NCContentPresenter.shared.messageNotification("_error_", description: description, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, errorCode: errorCode)
                 CCUtility.setPassword(account, password: nil)
             }
             

+ 1 - 1
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -321,7 +321,7 @@ import Alamofire
                             if errorCode == 401 || errorCode == 403 {
                             
                                 #if !EXTENSION
-                                NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode)
+                                NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, errorCode: errorCode, errorDescription: errorDescription)
                                 #endif
                                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
                             

+ 2 - 2
iOSClient/Networking/NCService.swift

@@ -129,7 +129,7 @@ class NCService: NSObject {
             } else {
                 
                 if errorCode == 401 || errorCode == 403 {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode)
+                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode, errorDescription: errorDescription)
                 }
             }
         }
@@ -278,7 +278,7 @@ class NCService: NSObject {
                 NCBrandColor.shared.settingThemingColor(account: account)
                 
                 if errorCode == 401 || errorCode == 403 {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode)
+                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode, errorDescription: errorDescription)
                 }
                 
             } else {