Browse Source

improvements error server unauth

marinofaggiana 5 years ago
parent
commit
ad2831f1dc

+ 1 - 5
iOSClient/AppDelegate.m

@@ -343,7 +343,6 @@ PKPushRegistry *pushRegistry;
                 _activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginBaseUrl];
                 
                 dispatch_async(dispatch_get_main_queue(), ^ {
-                    [_timerServerUnauthorized invalidate];
                     [_activeLoginWeb open:viewController];
                 });
             }
@@ -375,7 +374,6 @@ PKPushRegistry *pushRegistry;
                 }
 
                 dispatch_async(dispatch_get_main_queue(), ^ {
-                    [_timerServerUnauthorized invalidate];
                     [_activeLoginWeb open:viewController];
                 });
             }
@@ -388,7 +386,6 @@ PKPushRegistry *pushRegistry;
             _activeLoginWeb.urlBase = [[NCBrandOptions sharedInstance] loginBaseUrl];
             
             dispatch_async(dispatch_get_main_queue(), ^ {
-                [_timerServerUnauthorized invalidate];
                 [_activeLoginWeb open:viewController];
             });
             
@@ -401,7 +398,6 @@ PKPushRegistry *pushRegistry;
                 _activeLogin.loginType = loginType;
                 
                 dispatch_async(dispatch_get_main_queue(), ^ {
-                    [_timerServerUnauthorized invalidate];
                     [viewController presentViewController:_activeLogin animated:YES completion:nil];
                 });
             }
@@ -411,7 +407,7 @@ PKPushRegistry *pushRegistry;
 
 - (void)loginSuccess:(NSInteger)loginType
 {
-    self.timerServerUnauthorized = [NSTimer scheduledTimerWithTimeInterval:k_timerServerUnauthorized target:self selector:@selector(checkPassword) userInfo:nil repeats:YES];
+    //
 }
 - (void)webDismiss
 {

+ 3 - 0
iOSClient/Login/CCLogin.m

@@ -137,6 +137,9 @@
 - (void)viewDidAppear:(BOOL)animated
 {
     [super viewDidAppear:animated];
+    
+    // Stop timer
+    [appDelegate.timerServerUnauthorized invalidate];
 }
 
 //

+ 4 - 1
iOSClient/Login/CCLoginWeb.swift

@@ -55,7 +55,10 @@ public class CCLoginWeb: UIViewController {
         let webVC = SwiftModalWebVC(urlString: urlString, colorText: UIColor.black, colorDoneButton: UIColor.black, doneButtonVisible: doneButtonVisible, hideToolbar: true)
         webVC.delegateWeb = self
 
-        vc.present(webVC, animated: false, completion: nil)
+        vc.present(webVC, animated: false) {
+            // Stop timer
+            self.appDelegate.timerServerUnauthorized.invalidate()
+        }
     }
 }
 

+ 20 - 1
iOSClient/Networking/CCNetworking.m

@@ -388,6 +388,12 @@
 
 - (void)downloadFile:(tableMetadata *)metadata taskStatus:(NSInteger)taskStatus
 {
+    // No Password
+    if ([CCUtility getPassword:metadata.account].length == 0) {
+        [self.delegate downloadFileSuccessFailure:metadata.fileName fileID:metadata.fileID serverUrl:metadata.serverUrl selector:metadata.sessionSelector errorMessage:NSLocalizedString(@"_bad_username_password_", nil) errorCode:kOCErrorServerUnauthorized];
+        return;
+    }
+    
     // File exists ?
     tableLocalFile *localfile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
         
@@ -529,6 +535,8 @@
     [appDelegate.listProgressMetadata removeObjectForKey:fileID];
 #endif
     
+     tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
+    
     if (errorCode != 0) {
         
         if (errorCode == kCFURLErrorCancelled) {
@@ -537,6 +545,9 @@
             
         } else {
             
+            if (metadata && errorCode == kOCErrorServerUnauthorized)
+                [CCUtility setPassword:metadata.account password:nil];
+
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusDownloadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
         }
         
@@ -546,7 +557,6 @@
         
     } else {
         
-        tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
         if (!metadata) {
             
             NSLog(@"[LOG] Serious error internal download : metadata not found %@ ", fileName);
@@ -602,6 +612,12 @@
 
 - (void)uploadFile:(tableMetadata *)metadata taskStatus:(NSInteger)taskStatus
 {
+    // Password nil
+    if ([CCUtility getPassword:metadata.account].length == 0) {
+        [self.delegate uploadFileSuccessFailure:metadata.fileName fileID:metadata.fileID assetLocalIdentifier:metadata.assetLocalIdentifier serverUrl:metadata.serverUrl selector:metadata.sessionSelector errorMessage:NSLocalizedString(@"_bad_username_password_", nil) errorCode:kOCErrorServerUnauthorized];
+        return;
+    }
+    
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
     if (tableAccount == nil) {
         [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
@@ -1082,6 +1098,9 @@
             
         } else {
 
+            if (metadata && errorCode == kOCErrorServerUnauthorized)
+                [CCUtility setPassword:metadata.account password:nil];
+            
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusUploadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", tempFileID]];
             
             errorMessage = [CCError manageErrorKCF:errorCode withNumberError:YES];