Marino Faggiana 7 år sedan
förälder
incheckning
5c2642450c
2 ändrade filer med 45 tillägg och 14 borttagningar
  1. 17 4
      iOSClient/AppDelegate.m
  2. 28 10
      iOSClient/Login/CCLoginWeb.swift

+ 17 - 4
iOSClient/AppDelegate.m

@@ -346,10 +346,22 @@
     
     @synchronized (self) {
 
-        // Band : LoginWeb
-        if ([NCBrandOptions sharedInstance].use_login_web)
-            loginWeb = YES;
+        // only for Band : LoginWeb
+        if ([NCBrandOptions sharedInstance].use_login_web && _activeLoginWeb == nil) {
             
+            _activeLoginWeb = [CCLoginWeb new];
+            _activeLoginWeb.delegate = delegate;
+            _activeLoginWeb.loginType = loginType;
+                
+            dispatch_async(dispatch_get_main_queue(), ^ {
+                [_activeLoginWeb presentModalWithDefaultTheme:delegate];
+            });
+            return;
+        }
+        
+        // ------------------- Nextcloud -------------------------
+        //
+        
         // Login flow : LoginWeb
         if (loginType == loginModifyPasswordUser && [NCBrandOptions sharedInstance].use_login_web_flow) {
             tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
@@ -364,7 +376,8 @@
                 _activeLoginWeb = [CCLoginWeb new];
                 _activeLoginWeb.delegate = delegate;
                 _activeLoginWeb.loginType = loginType;
-                
+                _activeLoginWeb.urlBase = [self.activeUrl stringByAppendingString:flowEndpoint];
+
                 dispatch_async(dispatch_get_main_queue(), ^ {
                     [_activeLoginWeb presentModalWithDefaultTheme:delegate];
                 });

+ 28 - 10
iOSClient/Login/CCLoginWeb.swift

@@ -56,7 +56,7 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                 
         let urlString: String = url.absoluteString.lowercased()
         
-        if (urlString.contains(NCBrandOptions.sharedInstance.webLoginAutenticationProtocol) == true && urlString.contains("login") == true && (loginType == loginAdd || loginType == loginAddForced)) {
+        if (urlString.hasPrefix(NCBrandOptions.sharedInstance.webLoginAutenticationProtocol) == true && urlString.contains("login") == true) {
             
             let keyValue = url.path.components(separatedBy: "&")
             if (keyValue.count == 3) {
@@ -84,18 +84,36 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                 
                     let account : String = "\(username) \(serverUrl)"
                 
-                    NCManageDatabase.sharedInstance.deleteAccount(account)
-                    NCManageDatabase.sharedInstance.addAccount(account, url: serverUrl, user: username, password: password, loginFlow: true)
-                    
-                    guard let tableAccount = NCManageDatabase.sharedInstance.setAccountActive(account) else {
-                        return
+                    if (loginType == loginModifyPasswordUser && NCBrandOptions.sharedInstance.use_login_web_flow) {
+                        
+                        // Change Password
+                        guard let tableAccount = NCManageDatabase.sharedInstance.setAccountPassword(account, password: password) else {
+                            return
+                        }
+                        
+                        if (tableAccount.account == account) {
+                            appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
+                        }
+                        
+                        self.delegate?.loginSuccess(NSInteger(loginType.rawValue))
+                        self.viewController?.dismiss(animated: true, completion: nil)
                     }
-                
-                    if (tableAccount.account == account) {
                     
-                        appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
+                    if (loginType == loginAdd || loginType == loginAddForced) {
+                        
+                        // Add new account
+                        NCManageDatabase.sharedInstance.deleteAccount(account)
+                        NCManageDatabase.sharedInstance.addAccount(account, url: serverUrl, user: username, password: password, loginFlow: true)
+                        
+                        guard let tableAccount = NCManageDatabase.sharedInstance.setAccountActive(account) else {
+                            return
+                        }
+                        
+                        if (tableAccount.account == account) {
+                            appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
+                        }
+                        
                         self.delegate?.loginSuccess(NSInteger(loginType.rawValue))
-                
                         self.viewController?.dismiss(animated: true, completion: nil)
                     }
                 }