Browse Source

new webview login

marinofaggiana 5 years ago
parent
commit
e12c58e61f

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -438,7 +438,6 @@
 		F7B1FBCA1E72E3D1001781FE /* SwiftWebVCActivitySafari.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B1FBC31E72E3D1001781FE /* SwiftWebVCActivitySafari.swift */; };
 		F7B2DEF01F976854007CF4D2 /* NYMnemonic.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B2DEEF1F976785007CF4D2 /* NYMnemonic.m */; };
 		F7B2DEF11F976859007CF4D2 /* english.txt in Resources */ = {isa = PBXBuildFile; fileRef = F7B2DEED1F976785007CF4D2 /* english.txt */; };
-		F7B3A4EE1E97818A000DACE8 /* CCLoginWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */; };
 		F7B4F1CB1F44356F00B53B42 /* NCUchardet.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B4F1C81F44356F00B53B42 /* NCUchardet.m */; };
 		F7B6ACD622FC2BD4008AB646 /* NCXMLCommentsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B6ACD422FC2BD3008AB646 /* NCXMLCommentsParser.m */; };
 		F7B6ACD722FC2BD4008AB646 /* NCXMLCommentsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B6ACD422FC2BD3008AB646 /* NCXMLCommentsParser.m */; };
@@ -1250,7 +1249,6 @@
 		F7B2DEED1F976785007CF4D2 /* english.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = english.txt; sourceTree = "<group>"; };
 		F7B2DEEE1F976785007CF4D2 /* NYMnemonic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NYMnemonic.h; sourceTree = "<group>"; };
 		F7B2DEEF1F976785007CF4D2 /* NYMnemonic.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NYMnemonic.m; sourceTree = "<group>"; };
-		F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCLoginWeb.swift; sourceTree = "<group>"; };
 		F7B4F1C71F44356F00B53B42 /* NCUchardet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCUchardet.h; sourceTree = "<group>"; };
 		F7B4F1C81F44356F00B53B42 /* NCUchardet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCUchardet.m; sourceTree = "<group>"; };
 		F7B6ACD422FC2BD3008AB646 /* NCXMLCommentsParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCXMLCommentsParser.m; sourceTree = "<group>"; };
@@ -2575,7 +2573,6 @@
 				F75ADF441DC75FFE008A7347 /* CCLogin.storyboard */,
 				F7BF1B3F1D51E893000854F6 /* CCLogin.h */,
 				F7BF1B401D51E893000854F6 /* CCLogin.m */,
-				F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */,
 				F7AE00F4230D5F9E007ACF8A /* NCLoginWeb.swift */,
 				F745B252222D88AE00346520 /* NCLoginQRCode.swift */,
 			);
@@ -3795,7 +3792,6 @@
 				F7417DB3216CE925007D05F5 /* NCTrashSectionHeaderFooter.swift in Sources */,
 				F7F878AE1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */,
 				F762CB141EACB66200B38484 /* XLFormRightImageButton.m in Sources */,
-				F7B3A4EE1E97818A000DACE8 /* CCLoginWeb.swift in Sources */,
 				F73D71621F2673C200E233EB /* NCText.swift in Sources */,
 				F73B4EF81F470D9100BBEE4B /* LangDanishModel.cpp in Sources */,
 				F73B4F051F470D9100BBEE4B /* nsCharSetProber.cpp in Sources */,

+ 1 - 1
iOSClient/AppDelegate.m

@@ -36,7 +36,7 @@
 
 @class NCViewerRichdocument;
 
-@interface AppDelegate () <UNUserNotificationCenterDelegate, CCLoginDelegate, CCLoginDelegateWeb>
+@interface AppDelegate () <UNUserNotificationCenterDelegate, CCLoginDelegate, NCLoginDelegateWeb>
 {
 PKPushRegistry *pushRegistry;
 }

+ 2 - 2
iOSClient/Login/CCLogin.m

@@ -27,7 +27,7 @@
 #import "NCBridgeSwift.h"
 #import "NCNetworkingEndToEnd.h"
 
-@interface CCLogin () <CCLoginDelegateWeb, NCLoginQRCodeDelegate>
+@interface CCLogin () <NCLoginDelegateWeb, NCLoginQRCodeDelegate>
 {
     AppDelegate *appDelegate;
     UIView *rootView;
@@ -301,7 +301,7 @@
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark === CCLoginDelegateWeb ===
+#pragma mark === NCLoginDelegateWeb ===
 #pragma --------------------------------------------------------------------------------------------
 
 - (void)loginSuccess:(NSInteger)loginType

+ 0 - 161
iOSClient/Login/CCLoginWeb.swift

@@ -1,161 +0,0 @@
-//
-//  CCLoginWeb.swift
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 07/04/17.
-//  Copyright © 2017 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import UIKit
-
-@objc protocol CCLoginDelegateWeb: class {
-    func loginSuccess(_: NSInteger)
-    @objc optional func webDismiss()
-}
-
-public class CCLoginWeb: UIViewController {
-   
-    @objc weak var delegate: CCLoginDelegateWeb?
-    @objc var loginType: NSInteger = Int(k_login_Add)
-    @objc var urlBase = ""
-    
-    var doneButtonVisible: Bool = true
-    var viewController: UIViewController?
-    let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    
-    @objc func open(_ vc: UIViewController) {
-        
-        var urlString = urlBase
-        self.viewController = vc
-        
-        if loginType == k_login_Add_Forced {
-            doneButtonVisible = false
-        }
-        
-        // ADD k_flowEndpoint for Web Flow
-        if (NCBrandOptions.sharedInstance.use_login_web_personalized == false && urlBase != NCBrandOptions.sharedInstance.linkloginPreferredProviders) {
-            urlString =  urlBase+k_flowEndpoint
-        }
-        
-        let webVC = SwiftModalWebVC(urlString: urlString, colorText: UIColor.black, colorDoneButton: UIColor.black, doneButtonVisible: doneButtonVisible, hideToolbar: true)
-        webVC.delegateWeb = self
-
-        vc.present(webVC, animated: false) {
-            // Stop timer
-            self.appDelegate.timerErrorNetworking.invalidate()
-        }
-    }
-}
-
-extension CCLoginWeb: SwiftModalWebVCDelegate {
-    
-    public func didStartLoading() {
-        //print("Started loading.")
-    }
-    
-    public func didReceiveServerRedirectForProvisionalNavigation(url: URL) {
-                
-        let urlString: String = url.absoluteString.lowercased()
-        
-        if (urlString.hasPrefix(NCBrandOptions.sharedInstance.webLoginAutenticationProtocol) == true && urlString.contains("login") == true) {
-            
-            let keyValue = url.path.components(separatedBy: "&")
-            if (keyValue.count >= 3) {
-                
-                if (keyValue[0].contains("server:") && keyValue[1].contains("user:") && keyValue[2].contains("password:")) {
-                
-                    var serverUrl : String = keyValue[0].replacingOccurrences(of: "/server:", with: "")
-                    
-                    // Login Flow NC 12
-                    if (NCBrandOptions.sharedInstance.use_login_web_personalized == false && serverUrl.hasPrefix("http://") == false && serverUrl.hasPrefix("https://") == false) {
-                        serverUrl = urlBase
-                    }
-                    
-                    if (serverUrl.last == "/") {
-                        serverUrl = String(serverUrl.dropLast())
-                    }
-            
-                    let username : String = keyValue[1].replacingOccurrences(of: "user:", with: "").replacingOccurrences(of: "+", with: " ")
-                    let password : String = keyValue[2].replacingOccurrences(of: "password:", with: "")
-                
-                    let account : String = "\(username) \(serverUrl)"
-                
-                    // Login Flow
-                    if (loginType == k_login_Modify_Password && NCBrandOptions.sharedInstance.use_login_web_personalized == false) {
-                        
-                        // Verify if change the active account
-                        guard let activeAccount = NCManageDatabase.sharedInstance.getAccountActive() else {
-                            self.viewController?.dismiss(animated: true, completion: nil)
-                            return
-                        }
-                        if (activeAccount.account != account) {
-                            self.viewController?.dismiss(animated: true, completion: nil)
-                            return
-                        }
-                        
-                        // Change Password & setting active account
-                        CCUtility.setPassword(account, password: password)
-                        appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: appDelegate.activeUserID, activePassword: password)
-                        
-                        self.delegate?.loginSuccess(NSInteger(loginType))
-                        self.delegate?.webDismiss?()
-
-                        self.viewController?.dismiss(animated: true, completion: nil)
-                    }
-                    
-                    if (loginType == k_login_Add || loginType == k_login_Add_Forced) {
-                        
-                        // NO account found, clear
-                        if NCManageDatabase.sharedInstance.getAccounts() == nil {
-                            NCUtility.sharedInstance.removeAllSettings()
-                        }
-                        
-                        // STOP Intro
-                        CCUtility.setIntro(true)
-                        
-                        // 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 {
-                            self.viewController?.dismiss(animated: true, completion: nil)
-                            return
-                        }
-                        
-                        appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
-                        
-                        self.delegate?.loginSuccess(NSInteger(loginType))
-                        self.delegate?.webDismiss?()
-
-                        self.viewController?.dismiss(animated: true, completion: nil)
-                    }
-                }
-            }
-        }
-    }
-
-    public func didFinishLoading(success: Bool, url: URL) {
-        //print("Finished loading. Success: \(success).")
-    }
-    
-    public func webDismiss() {
-        self.delegate?.webDismiss?()
-    }
-}
-
-

+ 3 - 2
iOSClient/Login/NCLoginWeb.swift

@@ -36,7 +36,7 @@ class NCLoginWeb: UIViewController {
 
     @objc var urlBase = ""
     @objc var loginType: Int = 0
-    @objc weak var delegate: CCLoginDelegateWeb?
+    @objc weak var delegate: NCLoginDelegateWeb?
 
     @IBOutlet weak var buttonExit: UIButton!
 
@@ -58,9 +58,10 @@ class NCLoginWeb: UIViewController {
         }
         
         // button exit
-        self.view.bringSubviewToFront(buttonExit)
         if loginType == k_login_Add_Forced {
             buttonExit.isHidden = true
+        } else {
+            self.view.bringSubviewToFront(buttonExit)
         }
         
         loadWebPage(webView: webView!, url: URL(string: urlBase)!)

+ 2 - 5
iOSClient/Main/CCMain.m

@@ -36,7 +36,7 @@
 #import "NCNetworkingEndToEnd.h"
 #import "PKDownloadButton.h"
 
-@interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, CCLoginDelegate, CCLoginDelegateWeb, NCSelectDelegate, UITextFieldDelegate>
+@interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, CCLoginDelegate, NCLoginDelegateWeb, NCSelectDelegate, UITextFieldDelegate>
 {
     AppDelegate *appDelegate;
         
@@ -918,10 +918,7 @@
 
 - (void)loginSuccess:(NSInteger)loginType
 {
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-        // go to home sweet home
-        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
-    });    
+   [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
 }
 
 #pragma mark -

+ 1 - 1
iOSClient/Main/CCMore.swift

@@ -24,7 +24,7 @@
 
 import UIKit
 
-class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLoginDelegate, CCLoginDelegateWeb {
+class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLoginDelegate, NCLoginDelegateWeb {
 
     @IBOutlet weak var themingBackground: UIImageView!
     @IBOutlet weak var disclosureIndicator: UIImageView!

+ 1 - 1
iOSClient/Main/CCSplit.m

@@ -27,7 +27,7 @@
 #import "NCAutoUpload.h"
 #import "NCBridgeSwift.h"
 
-@interface CCSplit () <CCLoginDelegate, CCLoginDelegateWeb>
+@interface CCSplit () <CCLoginDelegate, NCLoginDelegateWeb>
 {
     AppDelegate *appDelegate;
     BOOL prevRunningInFullScreen;

+ 1 - 1
iOSClient/Settings/CCManageAccount.m

@@ -29,7 +29,7 @@
 
 #define actionSheetCancellaAccount 1
 
-@interface CCManageAccount () <CCLoginDelegate, CCLoginDelegateWeb>
+@interface CCManageAccount () <CCLoginDelegate, NCLoginDelegateWeb>
 {
     AppDelegate *appDelegate;
 }