Browse Source

login flow

Marino Faggiana 7 years ago
parent
commit
74bdfb591a

+ 2 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -144,7 +144,7 @@ class NCManageDatabase: NSObject {
     //MARK: -
     //MARK: Table Account
     
-    @objc func addAccount(_ account: String, url: String, user: String, password: String) {
+    @objc func addAccount(_ account: String, url: String, user: String, password: String, loginFlow: Bool) {
 
         let realm = try! Realm()
         
@@ -153,6 +153,7 @@ class NCManageDatabase: NSObject {
         let addObject = tableAccount()
             
         addObject.account = account
+        addObject.loginFlow = loginFlow
             
         // Brand
         if NCBrandOptions.sharedInstance.use_default_auto_upload {

+ 6 - 6
iOSClient/Login/CCLogin.m

@@ -211,14 +211,14 @@
     // Test Login Flow
     if ([self.baseUrl.text length] > 0 && _user.hidden && _password.hidden) {
         
-        NSString *url = self.baseUrl.text;
+        NSString *urlBase = self.baseUrl.text;
         // Remove trailing slash
         if ([self.baseUrl.text hasSuffix:@"/"])
-            url = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
+            urlBase = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
         // Add end point flow
-        url = [url stringByAppendingString:flowEndpoint];
+        urlBase = [urlBase stringByAppendingString:flowEndpoint];
         
-        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:0 timeoutInterval:20.0];
+        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlBase] cachePolicy:0 timeoutInterval:20.0];
         [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
         [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
 
@@ -255,7 +255,7 @@
                         appDelegate.activeLoginWeb = [CCLoginWeb new];
                         appDelegate.activeLoginWeb.loginType = _loginType;
                         appDelegate.activeLoginWeb.delegate = (id<CCLoginDelegateWeb>)self.delegate;
-                        appDelegate.activeLoginWeb.url = url;
+                        appDelegate.activeLoginWeb.urlBase = urlBase;
                         
                         [appDelegate.activeLoginWeb presentModalWithDefaultTheme:(UIViewController *)self.delegate];
                     }];
@@ -360,7 +360,7 @@
             } else {
 
                 [[NCManageDatabase sharedInstance] deleteAccount:account];
-                [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password];
+                [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
             
                 // Read User Profile
                 CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:account];

+ 15 - 4
iOSClient/Login/CCLoginWeb.swift

@@ -25,7 +25,7 @@ public class CCLoginWeb: UIViewController {
     
     @objc weak var delegate: CCLoginDelegateWeb?
     @objc var loginType = loginAdd
-    @objc var url = NCBrandOptions.sharedInstance.loginBaseUrl
+    @objc var urlBase = NCBrandOptions.sharedInstance.loginBaseUrl
     
     var viewController : UIViewController?
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -39,10 +39,11 @@ public class CCLoginWeb: UIViewController {
             doneButtonVisible = true
         }
         
-        let webVC = SwiftModalWebVC(urlString: url, theme: .custom, color: NCBrandColor.sharedInstance.brand, colorText: NCBrandColor.sharedInstance.brandText, doneButtonVisible: doneButtonVisible, hideToolbar: true)
+        let webVC = SwiftModalWebVC(urlString: urlBase, theme: .custom, color: NCBrandColor.sharedInstance.brand, colorText: NCBrandColor.sharedInstance.brandText, doneButtonVisible: doneButtonVisible, hideToolbar: true)
         webVC.delegateWeb = self
 
         vc.present(webVC, animated: false, completion: nil)
+        
     }
 }
 
@@ -65,6 +66,16 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                 
                     var serverUrl : String = keyValue[0].replacingOccurrences(of: "/server:", with: "")
                     
+                    // Login Flow
+                    if NCBrandOptions.sharedInstance.use_login_web_flow == true {
+                        
+                        if (self.urlBase.hasPrefix("http://")) {
+                            serverUrl = "http://" + serverUrl;
+                        } else if (self.urlBase.hasPrefix("https://")) {
+                            serverUrl = "https://" + serverUrl;
+                        }
+                    }
+                    
                     if (serverUrl.last == "/") {
                         serverUrl = String(serverUrl.dropLast())
                     }
@@ -75,8 +86,8 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                     let account : String = "\(username) \(serverUrl)"
                 
                     NCManageDatabase.sharedInstance.deleteAccount(account)
-                    NCManageDatabase.sharedInstance.addAccount(account, url: serverUrl, user: username, password: password)
-                                    
+                    NCManageDatabase.sharedInstance.addAccount(account, url: serverUrl, user: username, password: password, loginFlow: true)
+                    
                     guard let tableAccount = NCManageDatabase.sharedInstance.setAccountActive(account) else {
                         return
                     }