Преглед на файлове

improvements error server unauth

marinofaggiana преди 5 години
родител
ревизия
f4dc0b3443
променени са 7 файла, в които са добавени 27 реда и са изтрити 57 реда
  1. 1 0
      iOSClient/AppDelegate.h
  2. 13 1
      iOSClient/AppDelegate.m
  3. 1 0
      iOSClient/CCGlobal.h
  4. 0 4
      iOSClient/Favorites/CCFavorites.m
  5. 10 42
      iOSClient/Main/CCMain.m
  6. 1 3
      iOSClient/Shares/NCShares.m
  7. 1 7
      iOSClient/Trash/NCTrash.swift

+ 1 - 0
iOSClient/AppDelegate.h

@@ -46,6 +46,7 @@
 // Timer Process
 @property (nonatomic, strong) NSTimer *timerProcessAutoDownloadUpload;
 @property (nonatomic, strong) NSTimer *timerUpdateApplicationIconBadgeNumber;
+@property (nonatomic, strong) NSTimer *timerServerUnauthorized;
 
 // For LMMediaPlayerView
 @property (strong, nonatomic) UIWindow *window;

+ 13 - 1
iOSClient/AppDelegate.m

@@ -200,6 +200,7 @@ PKPushRegistry *pushRegistry;
     // Start Timer
     self.timerProcessAutoDownloadUpload = [NSTimer scheduledTimerWithTimeInterval:k_timerProcessAutoDownloadUpload target:self selector:@selector(loadAutoDownloadUpload) userInfo:nil repeats:YES];
     self.timerUpdateApplicationIconBadgeNumber = [NSTimer scheduledTimerWithTimeInterval:k_timerUpdateApplicationIconBadgeNumber target:self selector:@selector(updateApplicationIconBadgeNumber) userInfo:nil repeats:YES];
+    self.timerServerUnauthorized = [NSTimer scheduledTimerWithTimeInterval:k_timerServerUnauthorized target:self selector:@selector(checkPassword) userInfo:nil repeats:YES];
 
     // Fabric
     if (![CCUtility getDisableCrashservice]) {
@@ -311,9 +312,20 @@ PKPushRegistry *pushRegistry;
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Login =====
+#pragma mark ===== Login / checkPassword: ServerUnauthorized =====
 #pragma --------------------------------------------------------------------------------------------
 
+- (void)checkPassword
+{
+    // test
+    if (self.activeAccount.length == 0 || self.maintenanceMode || self.pushKitToken.length == 0)
+        return;
+    
+    if ([CCUtility getPassword:self.activeAccount].length == 0) {
+        [self openLoginView:self.window.rootViewController delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
+    }
+}
+
 - (void)openLoginView:(UIViewController *)viewController delegate:(id)delegate loginType:(NSInteger)loginType selector:(NSInteger)selector
 {
     BOOL loginWebFlow = NO;

+ 1 - 0
iOSClient/CCGlobal.h

@@ -171,6 +171,7 @@
 // Timer
 #define k_timerProcessAutoDownloadUpload                5
 #define k_timerUpdateApplicationIconBadgeNumber         3
+#define k_timerServerUnauthorized                       3
 
 // ConcurrentOperation
 #define k_maxHTTPConnectionsPerHost                     5

+ 0 - 4
iOSClient/Favorites/CCFavorites.m

@@ -179,8 +179,6 @@
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadata.fileID favorite:favorite];
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadata.fileID action:k_action_MOD];
-        } else if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:appDelegate.activeMain loginType:k_login_Modify_Password selector:k_intro_login];
         } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
@@ -246,8 +244,6 @@
             
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
             
-        } else if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:appDelegate.activeMain loginType:k_login_Modify_Password selector:k_intro_login];
         } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {

+ 10 - 42
iOSClient/Main/CCMain.m

@@ -1131,8 +1131,6 @@
                 [self readFolder:metadata.serverUrl];
             }
             
-        } else if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
         } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
@@ -1263,8 +1261,6 @@
         
         if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
-        } else if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
         } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
@@ -1326,9 +1322,7 @@
             
         } else {
             
-            if (errorCode == kOCErrorServerUnauthorized) {
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            if (errorCode == NSURLErrorServerCertificateUntrusted) {
                 [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
             } else if (errorCode != 0) {
                 [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
@@ -1516,9 +1510,7 @@
                 
             } else if (errorCode != 0) {
                 
-                if (errorCode == kOCErrorServerUnauthorized) {
-                    [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-                } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+                if (errorCode == NSURLErrorServerCertificateUntrusted) {
                     [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
                 } else if (errorCode == kOCErrorServerPathNotFound) {
                 
@@ -1603,9 +1595,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized) {
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            if (errorCode == NSURLErrorServerCertificateUntrusted) {
                 [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
             } else if (errorCode == kOCErrorServerPathNotFound) {
             
@@ -1813,9 +1803,7 @@
             [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileIDTemp]];
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
             
-            if (errorCode == kOCErrorServerUnauthorized) {
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            if (errorCode == NSURLErrorServerCertificateUntrusted) {
                 [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
             } else if (errorCode != 0) {
                 [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
@@ -1931,10 +1919,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
     }];
     
@@ -1957,10 +1942,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
         if (_shareOC)
@@ -1992,10 +1974,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
         if (_shareOC)
@@ -2019,10 +1998,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
         if (_shareOC)
@@ -2048,10 +2024,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
 
     }];
@@ -2073,10 +2046,7 @@
             
         } else if (errorCode != 0) {
             
-            if (errorCode == kOCErrorServerUnauthorized)
-                [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
-            else
-                [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+            [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
         if (_shareOC)
@@ -2164,8 +2134,6 @@
                 [appDelegate startLoadAutoDownloadUpload];
             }
             
-        } else if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
         } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {

+ 1 - 3
iOSClient/Shares/NCShares.m

@@ -204,9 +204,7 @@
             
             [self reloadDatasource];
             
-        } if (errorCode == kOCErrorServerUnauthorized) {
-            [appDelegate openLoginView:self delegate:appDelegate.activeMain loginType:k_login_Modify_Password selector:k_intro_login];
-        } else if (errorCode == NSURLErrorServerCertificateUntrusted) {
+        } if (errorCode == NSURLErrorServerCertificateUntrusted) {
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
         } else if (errorCode != 0) {
             [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];

+ 1 - 7
iOSClient/Trash/NCTrash.swift

@@ -680,8 +680,6 @@ extension NCTrash {
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path, account: self.appDelegate.activeAccount)
                 NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
-            } else if errorCode == kOCErrorServerUnauthorized {
-                self.appDelegate.openLoginView(self, delegate: self.appDelegate.activeMain, loginType: Int(k_login_Modify_Password), selector: Int(k_intro_login))
             } else if errorCode != 0 {
                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
             } else {
@@ -712,9 +710,7 @@ extension NCTrash {
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 NCManageDatabase.sharedInstance.deleteTrash(fileID: fileID, account: account!)
                 self.loadDatasource()
-            } else if errorCode == kOCErrorServerUnauthorized {
-                self.appDelegate.openLoginView(self, delegate: self.appDelegate.activeMain, loginType: Int(k_login_Modify_Password), selector: Int(k_intro_login))
-            } else if errorCode != 0 {
+            }  else if errorCode != 0 {
                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
             } else {
                 print("[LOG] It has been changed user during networking process, error.")
@@ -727,8 +723,6 @@ extension NCTrash {
         OCNetworking.sharedManager().emptyTrash(withAccount: appDelegate.activeAccount, completion: { (account, message, errorCode) in
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 NCManageDatabase.sharedInstance.deleteTrash(fileID: nil, account: self.appDelegate.activeAccount)
-            } else if errorCode == kOCErrorServerUnauthorized {
-                self.appDelegate.openLoginView(self, delegate: self.appDelegate.activeMain, loginType: Int(k_login_Modify_Password), selector: Int(k_intro_login))
             } else if errorCode != 0 {
                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
             } else {