소스 검색

fix old code

Marino Faggiana 6 년 전
부모
커밋
e9bb7fd8df

+ 60 - 0
iOSClient/Login/CCLogin.m

@@ -369,6 +369,65 @@
 
 - (void)loginCloudUrl:(NSString *)url user:(NSString *)user password:(NSString *)password
 {
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:user withUserID:user withPassword:password withUrl:nil];
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        self.login.enabled = NO;
+        self.loadingBaseUrl.hidden = NO;
+    });
+    
+    [ocNetworking checkServer:[NSString stringWithFormat:@"%@%@", url, webDAV] success:^{
+        
+        // account
+        NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
+        
+        if (_loginType == loginModifyPasswordUser) {
+            
+            // Change Password
+            tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
+            
+            // Setting appDelegate active account
+            [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
+            
+            [self.delegate loginSuccess:_loginType];
+            
+            [self dismissViewControllerAnimated:YES completion:nil];
+            
+        } else {
+            
+            [[NCManageDatabase sharedInstance] deleteAccount:account];
+            [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
+            
+            tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
+            
+            // Setting appDelegate active account
+            [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
+            
+            [self.delegate loginSuccess:_loginType];
+            
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                [self dismissViewControllerAnimated:YES completion:nil];
+            });
+        }
+                
+    } failure:^(NSString *message, NSInteger errorCode) {
+        
+        if (errorCode != NSURLErrorServerCertificateUntrusted) {
+            
+            NSString *messageAlert = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedStringFromTable(@"_not_possible_connect_to_server_", @"Error", nil), message];
+            
+            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:messageAlert preferredStyle:UIAlertControllerStyleAlert];
+            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+            
+            [alertController addAction:okAction];
+            [self presentViewController:alertController animated:YES completion:nil];
+        }
+        
+        self.login.enabled = YES;
+        self.loadingBaseUrl.hidden = YES;
+    }];
+    
+    /*
     NSError *error = [[NCNetworkingSync sharedManager] checkServer:[NSString stringWithFormat:@"%@%@", url, webDAV] user:user userID:user password:password];
 
     dispatch_async(dispatch_get_main_queue(), ^{
@@ -428,6 +487,7 @@
         self.login.enabled = YES;
         self.loadingBaseUrl.hidden = YES;
     });
+    */
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 0 - 1
iOSClient/Networking/NCNetworkingSync.h

@@ -14,7 +14,6 @@
 + (NCNetworkingSync *)sharedManager;
 
 - (NSError *)uploadFile:(NSString *)localFilePathName remoteFilePathName:(NSString *)remoteFilePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password;
-- (NSError *)checkServer:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password;
 - (NSError *)readFile:(NSString *)filePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray **)items;
 - (NSError *)readFolder:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray **)items;
 - (NSError *)createFolder:(NSString *)folderPathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url encrypted:(BOOL)encrypted fileID:(NSString **)fileID;

+ 0 - 26
iOSClient/Networking/NCNetworkingSync.m

@@ -72,32 +72,6 @@
      return returnError;
 }
 
-- (NSError *)checkServer:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password
-{
-    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
-    __block NSError *returnError = nil;
-    
-    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
-    
-    [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-    
-    [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-        
-        dispatch_semaphore_signal(semaphore);
-        
-    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-        
-        returnError = [self getError:response error:error descriptionDefault:@"_error_check_server_"];
-        dispatch_semaphore_signal(semaphore);
-    }];
-    
-    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
-        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
-    
-    return returnError;
-}
-
 - (NSError *)readFile:(NSString *)filePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray  **)items
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;

+ 1 - 0
iOSClient/Networking/OCNetworking.h

@@ -42,6 +42,7 @@
 @property (nonatomic, assign) BOOL isExecuting;
 @property (nonatomic, assign) BOOL isFinished;
 
+- (void)checkServer:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (NSURLSessionTask *)downloadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void (^)(int64_t length, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (NSURLSessionTask *)uploadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;

+ 33 - 0
iOSClient/Networking/OCNetworking.m

@@ -128,6 +128,39 @@
 #endif
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Check Server =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)checkServer:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    
+    [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+        
+    [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+        
+        success();
+            
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        NSString *message;
+
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
+            errorCode = error.code;
+        
+        // Error
+        if (errorCode == 503)
+            message = NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil);
+        else
+            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
+    
+        failure(message, errorCode);
+    }];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== download =====
 #pragma --------------------------------------------------------------------------------------------

+ 2 - 0
iOSClient/Settings/CCAdvanced.m

@@ -479,6 +479,8 @@
             
             [CCUtility deleteAllChainStore];
             
+            [self emptyGroupFileProviderStorage];
+
             [self emptyDocumentsDirectory];
             
             [self emptyLibraryDirectory];