Marino Faggiana 7 anni fa
parent
commit
64d7c7dbff

+ 1 - 1
iOSClient/Brand/NCBrand.swift

@@ -87,7 +87,7 @@ class NCBrandColor: NSObject {
     
     // Options
     @objc public let use_login_web:                   Bool = false
-    @objc public let use_login_web_flow:              Bool = false
+    @objc public let use_login_web_flow:              Bool = true
     @objc public let use_firebase:                    Bool = false
     @objc public let use_default_auto_upload:         Bool = false
     @objc public let use_themingColor:                Bool = true

+ 1 - 0
iOSClient/Database/NCDatabase.swift

@@ -41,6 +41,7 @@ class tableAccount: Object {
     @objc dynamic var displayName = ""
     @objc dynamic var email = ""
     @objc dynamic var enabled: Bool = false
+    @objc dynamic var loginFlow: Bool = false
     @objc dynamic var optimization = NSDate()
     @objc dynamic var password = ""
     @objc dynamic var phone = ""

+ 3 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -57,13 +57,14 @@ class NCManageDatabase: NSObject {
         let config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 14,
+            schemaVersion: 15,
             
             // 10 : Version 2.18.0
             // 11 : Version 2.18.2
             // 12 : Version 2.19.0.5
             // 13 : Version 2.19.0.14
-            // 14 : ...
+            // 14 : Version 2.19.0.xx
+            // 15 : Version 2.19.2
             
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0

+ 73 - 25
iOSClient/Login/CCLogin.m

@@ -88,14 +88,19 @@
     
     // Brand
     if ([NCBrandOptions sharedInstance].disable_request_login_url) {
-        
         _baseUrl.text = [NCBrandOptions sharedInstance].loginBaseUrl;
         _imageBaseUrl.hidden = YES;
         _baseUrl.hidden = YES;
     }
 
     if (_loginType == loginAdd) {
-        
+        // Login Flow ?
+        if ([NCBrandOptions sharedInstance].use_login_web_flow) {
+            _imageUser.hidden = YES;
+            _user.hidden = YES;
+            _imagePassword.hidden = YES;
+            _password.hidden = YES;
+        }
     }
     
     if (_loginType == loginAddForced) {
@@ -185,44 +190,82 @@
     if(![self.baseUrl.text hasPrefix:@"https"] && ![self.baseUrl.text hasPrefix:@"http"]) {
       self.baseUrl.text = [NSString stringWithFormat:@"https://%@",self.baseUrl.text];
     }
-    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.baseUrl.text] cachePolicy:0 timeoutInterval:20.0];
-    [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
     
-    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
+    // Test Login Flow
+    if ([self.baseUrl.text length] > 0 && _user.hidden == YES && _password.hidden == YES) {
+        
+        NSString *url = self.baseUrl.text;
+        if ([url hasSuffix:@"/"]) url = [url substringToIndex:[url length] - 1];
+        url = [url stringByAppendingString:flowEndpoint];
+        
+        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:0 timeoutInterval:20.0];
+        
+        [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
+        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) {
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                
+                self.login.enabled = YES;
+                self.loadingBaseUrl.hidden = YES;
+                
+                if (error) {
+                    
+                    NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);
+
+                } else {
+                    
+                    
+                }
+                
+            });
+        }];
+        
+        [task resume];
+        
+    } else {
+    
+        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.baseUrl.text] cachePolicy:0 timeoutInterval:20.0];
+        [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
     
-    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
+        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) {
         
-        dispatch_async(dispatch_get_main_queue(), ^{
+            dispatch_async(dispatch_get_main_queue(), ^{
             
-            self.login.enabled = YES;
-            self.loadingBaseUrl.hidden = YES;
+                self.login.enabled = YES;
+                self.loadingBaseUrl.hidden = YES;
         
-            if (error != nil) {
+                if (error != nil) {
             
-                NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);
+                    NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);
             
-                // self signed certificate
-                if ([error code] == NSURLErrorServerCertificateUntrusted) {
+                    // self signed certificate
+                    if ([error code] == NSURLErrorServerCertificateUntrusted) {
                 
-                    NSLog(@"[LOG] Error NSURLErrorServerCertificateUntrusted");
+                        NSLog(@"[LOG] Error NSURLErrorServerCertificateUntrusted");
                 
-                    [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
+                        [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
                 
-                } else {
+                    } else {
                     
-                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
-                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
+                        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
                     
-                    [alertController addAction:okAction];
-                    [self presentViewController:alertController animated:YES completion:nil];
+                        [alertController addAction:okAction];
+                        [self presentViewController:alertController animated:YES completion:nil];
+                    }
                 }
-            }
-        });
+            });
         
-    }];
+        }];
     
-    [task resume];
+        [task resume];
+    }
 }
 
 - (void)trustedCerticateAccepted
@@ -409,6 +452,11 @@
 
 - (IBAction)handleButtonLogin:(id)sender
 {
+    if ([self.baseUrl.text length] > 0 && _user.hidden == YES && _password.hidden == YES) {
+        [self testUrl];
+        return;
+    }
+    
     if ([self.baseUrl.text length] > 0 && [self.user.text length] && [self.password.text length]) {
         
         // remove last char if /