marinofaggiana 4 年 前
コミット
53ad2df80f
2 ファイル変更38 行追加27 行削除
  1. 3 3
      iOSClient/Login/NCLogin.storyboard
  2. 35 24
      iOSClient/Login/NCLogin.swift

+ 3 - 3
iOSClient/Login/NCLogin.storyboard

@@ -32,7 +32,7 @@
                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                 <textInputTraits key="textInputTraits" autocorrectionType="no" keyboardType="URL" returnKeyType="done"/>
                                 <connections>
-                                    <action selector="handlebaseUrlchange:" destination="yj9-jo-WIn" eventType="editingDidEnd" id="efj-33-NT5"/>
+                                    <action selector="actionBaseUrlchange:" destination="yj9-jo-WIn" eventType="editingDidEnd" id="viw-GY-1Za"/>
                                 </connections>
                             </textField>
                             <textField opaque="NO" clipsSubviews="YES" tag="2" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Username" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="1Gf-Bw-Nim">
@@ -108,7 +108,7 @@
                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                 <state key="normal" title="Login type view"/>
                                 <connections>
-                                    <action selector="handleLoginTypeView:" destination="yj9-jo-WIn" eventType="touchUpInside" id="V2I-Nr-nOu"/>
+                                    <action selector="actionLoginModeButton:" destination="yj9-jo-WIn" eventType="touchUpInside" id="bqY-ne-nbT"/>
                                 </connections>
                             </button>
                             <activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="Kfq-Bg-a0E">
@@ -167,7 +167,7 @@
                         <outlet property="imagePassword" destination="7q8-rl-x2M" id="Cr5-Te-Rkq"/>
                         <outlet property="imageUser" destination="4OF-5u-Hd1" id="MJa-4H-w7m"/>
                         <outlet property="loginButton" destination="HQd-pF-3cE" id="XOc-dS-QZ8"/>
-                        <outlet property="loginTypeViewButton" destination="owR-PS-F32" id="7dm-jk-nek"/>
+                        <outlet property="loginModeButton" destination="owR-PS-F32" id="iXW-wC-T2H"/>
                         <outlet property="password" destination="jU7-Iw-XfU" id="OWi-V0-Eij"/>
                         <outlet property="qrCode" destination="6tp-bh-Z9k" id="Tw3-op-BgR"/>
                         <outlet property="toggleVisiblePasswordButton" destination="fhk-o9-J0l" id="e0X-WA-5cz"/>

+ 35 - 24
iOSClient/Login/NCLogin.swift

@@ -40,10 +40,15 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
     @IBOutlet weak var loginButton: UIButton!
     @IBOutlet weak var toggleVisiblePasswordButton: UIButton!
-    @IBOutlet weak var loginTypeViewButton: UIButton!
+    @IBOutlet weak var loginModeButton: UIButton!
     
     @IBOutlet weak var qrCode: UIButton!
 
+    enum loginMode {
+        case traditional, webFlow
+    }
+    var currentLoginMode: loginMode = .webFlow
+    
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var textColor: UIColor = .white
     var textColorOpponent: UIColor = .black
@@ -103,8 +108,8 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         loginButton.clipsToBounds = true
         
         // type of login
-        loginTypeViewButton.setTitle(NSLocalizedString("_traditional_login_", comment: ""), for: .normal)
-        loginTypeViewButton.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
+        loginModeButton.setTitle(NSLocalizedString("_traditional_login_", comment: ""), for: .normal)
+        loginModeButton.setTitleColor(textColor.withAlphaComponent(0.5), for: .normal)
      
         // brand
         if NCBrandOptions.shared.disable_request_login_url {
@@ -171,35 +176,39 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         dismiss(animated: true) { }
     }
 
-    @IBAction func handlebaseUrlchange(_ sender: Any) {
+    @IBAction func actionBaseUrlchange(_ sender: Any) {
+                
+        guard var url = baseUrl.text?.trimmingCharacters(in: .whitespacesAndNewlines) else { return }
+        if url.hasSuffix("/") { url = String(url.dropLast()) }
+        if url.count == 0 { return }
         
-        if baseUrl.text?.count ?? 0 > 0 && !user.isHidden && !password.isHidden {
-            isUrlValid()
-        }
+        isUrlValid(url: url)
     }
     
     @IBAction func handleButtonLogin(_ sender: Any) {
         
-        if baseUrl.text?.count ?? 0 > 0 && !user.isHidden && !password.isHidden {
-            
-            isUrlValid()
+        guard var url = baseUrl.text?.trimmingCharacters(in: .whitespacesAndNewlines) else { return }
+        if url.hasSuffix("/") { url = String(url.dropLast()) }
+        if url.count == 0 { return }
+
+        if  currentLoginMode == .webFlow {
             
-        } else if baseUrl.text?.count ?? 0 > 0 && user.text?.count ?? 0 > 0 && password.text?.count ?? 0 > 0 {
+            isUrlValid(url: url)
             
-            guard var url = baseUrl.text else { return }
-            if url.hasSuffix("/") {
-                url = String(url.dropLast())
-            }
+        } else  {
             
+            guard let username = user.text else { return }
+            guard let password = password.text else { return }
+
             loginButton.isEnabled = false
             activity.startAnimating()
             
-            NCCommunication.shared.getAppPassword(serverUrl: url, username: user.text!, password: password.text!) { (token, errorCode, errorDescription) in
+            NCCommunication.shared.getAppPassword(serverUrl: url, username:  username, password: password) { (token, errorCode, errorDescription) in
                 
                 self.loginButton.isEnabled = true
                 self.activity.stopAnimating()
                 
-                self.standardLogin(urlBase: url, user: self.user.text ?? "", token: token ?? "", errorCode: errorCode, errorDescription: errorDescription)
+                self.standardLogin(urlBase: url, user: username, token: token ?? "", errorCode: errorCode, errorDescription: errorDescription)
             }
         }
     }
@@ -212,25 +221,27 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         password.text = currentPassword
     }
     
-    @IBAction func handleLoginTypeView(_ sender: Any) {
-        
-        if user.isHidden && password.isHidden {
+    @IBAction func actionLoginModeButton(_ sender: Any) {
+                
+        if currentLoginMode == .traditional {
             
+            currentLoginMode = .webFlow
             imageUser.isHidden = false
             user.isHidden = false
             imagePassword.isHidden = false
             password.isHidden = false
             
-            loginTypeViewButton.setTitle(NSLocalizedString("_web_login_", comment: ""), for: .normal)
+            loginModeButton.setTitle(NSLocalizedString("_web_login_", comment: ""), for: .normal)
             
         } else {
             
+            currentLoginMode = .traditional
             imageUser.isHidden = true
             user.isHidden = true
             imagePassword.isHidden = true
             password.isHidden = true
             
-            loginTypeViewButton.setTitle(NSLocalizedString("_traditional_login_", comment: ""), for: .normal)
+            loginModeButton.setTitle(NSLocalizedString("_traditional_login_", comment: ""), for: .normal)
         }
     }
     
@@ -242,7 +253,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
     
     // MARK: - Login
 
-    func isUrlValid() {
+    func isUrlValid(url: String) {
 
         // Check whether baseUrl contain protocol. If not add https:// by default.
         if (baseUrl.text?.hasPrefix("https") ?? false) == false && (baseUrl.text?.hasPrefix("http") ?? false) == false {
@@ -289,7 +300,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                         
                     } else if versionMajor < NCGlobal.shared.nextcloudVersion12 {
                         
-                        self.loginTypeViewButton.isHidden = true
+                        self.loginModeButton.isHidden = true
                         
                         self.imageUser.isHidden = false
                         self.user.isHidden = false