marinofaggiana před 4 roky
rodič
revize
8728c7d025

+ 1 - 1
Cartfile

@@ -4,7 +4,7 @@ github "kishikawakatsumi/UICKeyChainStore" "v2.1.2"
 github "MortimerGoro/MGSwipeTableCell" "1.6.8"
 github "dzenbot/DZNEmptyDataSet" "v1.8.1"
 github "jdg/MBProgressHUD" "1.1.0"
-github "realm/realm-cocoa"
+github "realm/realm-cocoa" "v4.4.1"
 github "SVGKit/SVGKit" "3.x"
 github "WeTransfer/WeScan" "1.2.0"
 github "malcommac/SwiftRichString"

+ 1 - 1
Cartfile.resolved

@@ -18,7 +18,7 @@ github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
 github "marinofaggiana/KTVHTTPCache" "2.0.2"
 github "marinofaggiana/TOPasscodeViewController" "0.0.6"
 github "marinofaggiana/XLForm" "eb9381ad8129f60402bf412250fb31b95a628a08"
-github "nextcloud/ios-communication-library" "ea8e7efdac21aae1e613bcc6eb9c27b1c7235fd9"
+github "nextcloud/ios-communication-library" "47281fecc92d726169d4da6f9b3e11316d529d2f"
 github "realm/realm-cocoa" "v4.4.1"
 github "rechsteiner/Parchment" "v1.7.0"
 github "scenee/FloatingPanel" "v1.7.4"

+ 8 - 6
iOSClient/Login/CCLogin.m

@@ -331,12 +331,14 @@
             self.login.enabled = NO;
             [self.activity startAnimating];
             
-            [[OCNetworking sharedManager] checkServerUrl:[NSString stringWithFormat:@"%@%@", url, k_webDAV] user:user userID:user password:token completion:^(NSString *message, NSInteger errorCode) {
-
+            NSString *serverUrl = [NSString stringWithFormat:@"%@%@", url, k_webDAV];
+            
+            [[NCCommunication shared] checkServerWithServerUrl:serverUrl completionHandler:^(NSInteger errorCode, NSString *errorDescription) {
+                
                 [self.activity stopAnimating];
                 self.login.enabled = YES;
                 
-                [self AfterLoginWithUrl:url user:user token:token errorCode:errorCode message:message];
+                [self AfterLoginWithUrl:url user:user token:token errorCode:errorCode message:errorDescription];
             }];
         }
     }
@@ -372,12 +374,12 @@
         self.login.enabled = NO;
         [self.activity startAnimating];
 
-        [[OCNetworking sharedManager] getAppPassword:url username:user password:password completion:^(NSString *token, NSString *message, NSInteger errorCode) {
+        [[NCCommunication shared] getAppPasswordWithServerUrl:url username:user password:password customUserAgent:nil completionHandler:^(NSString *token, NSInteger errorCode, NSString *errorDescription) {
             
             [self.activity stopAnimating];
             self.login.enabled = YES;
-
-            [self AfterLoginWithUrl:url user:user token:token errorCode:errorCode message:message];
+            
+            [self AfterLoginWithUrl:url user:user token:token errorCode:errorCode message:errorDescription];
         }];
     }
 }

+ 5 - 4
iOSClient/Login/NCAppConfigView.swift

@@ -22,6 +22,7 @@
 //
 
 import Foundation
+import NCCommunication
 
 class NCAppConfigView: UIViewController {
 
@@ -72,9 +73,9 @@ class NCAppConfigView: UIViewController {
             return
         }
         
-        OCNetworking.sharedManager()?.getAppPassword(serverUrl, username: username, password: password, completion: { (token, message, errorCode) in
+        NCCommunication.shared.getAppPassword(serverUrl: serverUrl, username: username, password: password, customUserAgent: nil) { (token, errorCode, errorDescription) in
             DispatchQueue.main.async {
-                if errorCode == 0 {
+                if errorCode == 0 && token != nil {
                     let account: String = "\(username) \(serverUrl)"
                     
                     // NO account found, clear
@@ -95,10 +96,10 @@ class NCAppConfigView: UIViewController {
                     
                     self.dismiss(animated: true) {}
                 } else {
-                    NCContentPresenter.shared.messageNotification("_error_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                    NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                 }
             }
-        })
+        }
     }
     
     override func viewDidDisappear(_ animated: Bool) {

+ 0 - 5
iOSClient/Networking/OCNetworking.h

@@ -35,11 +35,6 @@
 
 - (OCCommunication *)sharedOCCommunication;
 
-#pragma mark ===== Server =====
-
-- (void)checkServerUrl:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password completion:(void (^)(NSString *message, NSInteger errorCode))completion;
-- (void)getAppPassword:(NSString *)serverUrl username:(NSString *)username password:(NSString *)password completion:(void(^)(NSString *token, NSString *message, NSInteger errorCode))completion;
-
 #pragma mark ===== Share =====
 
 - (void)readShareWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion;

+ 0 - 74
iOSClient/Networking/OCNetworking.m

@@ -107,80 +107,6 @@
     return sharedOCCommunication;
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Server =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)checkServerUrl:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password completion:(void (^)(NSString *message, NSInteger errorCode))completion
-{
-    OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
-    
-    [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-        
-    [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-        
-        completion(nil, 0);
-            
-    } 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 = NSLocalizedString(@"_server_error_retry_", nil);
-        else
-            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-    
-        completion(message, errorCode);
-    }];
-}
-
-- (void)getAppPassword:(NSString *)serverUrl username:(NSString *)username password:(NSString *)password completion:(void(^)(NSString *token, NSString *message, NSInteger errorCode))completion
-{
-    NSData *authData = [[NSString stringWithFormat:@"%@:%@", username, password] dataUsingEncoding:NSUTF8StringEncoding];
-    NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
-    NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/core/getapppassword", serverUrl];
-    
-    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
-    [request setValue:authValue forHTTPHeaderField:@"Authorization"];
-    [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
-    [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-    
-    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
-    
-    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
-        
-        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
-        NSInteger errorCode = 0;
-        NSString *message = @"";
-        NSString *token = nil;
-        
-        if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {
-            
-            NCXMLGetAppPasswordParser *parser = [NCXMLGetAppPasswordParser new];
-            [parser initParserWithData:data];
-            token = parser.token;
-            
-        } else {
-            
-            errorCode = httpResponse.statusCode;
-            message = [NSHTTPURLResponse localizedStringForStatusCode:httpResponse.statusCode];
-        }
-    
-        dispatch_async(dispatch_get_main_queue(), ^{
-            completion(token, message, errorCode);
-        });
-    }];
-    
-    [task resume];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Share =====
 #pragma --------------------------------------------------------------------------------------------