Browse Source

Passcode - Start

Marino Faggiana 8 years ago
parent
commit
c9106570bf

+ 4 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -4391,7 +4391,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.Picker;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SKIP_INSTALL = YES;
-				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG NC";
 				SWIFT_OBJC_BRIDGING_HEADER = "Picker/Picker-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_VERSION = 3.0;
@@ -4423,6 +4423,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.Picker;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SKIP_INSTALL = YES;
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = NC;
 				SWIFT_OBJC_BRIDGING_HEADER = "Picker/Picker-Bridging-Header.h";
 				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
@@ -4452,7 +4453,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.PickerFileProvider;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SKIP_INSTALL = YES;
-				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG NC";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
@@ -4481,6 +4482,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.PickerFileProvider;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SKIP_INSTALL = YES;
+				SWIFT_ACTIVE_COMPILATION_CONDITIONS = NC;
 				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};

+ 2 - 2
Picker/Base.lproj/MainInterface.storyboard

@@ -30,7 +30,7 @@
                                         <rect key="frame" x="0.0" y="28" width="375" height="50"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0H6-U8-fd4" id="44X-Sr-gc0">
-                                            <rect key="frame" x="0.0" y="0.0" width="375" height="49"/>
+                                            <rect key="frame" x="0.0" y="0.0" width="375" height="49.5"/>
                                             <autoresizingMask key="autoresizingMask"/>
                                             <subviews>
                                                 <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wk9-rb-4yv">
@@ -69,7 +69,7 @@
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
                                 <items>
                                     <barButtonItem style="plain" systemItem="flexibleSpace" id="Wcn-Rh-qba"/>
-                                    <barButtonItem title="Item" id="LlY-NF-IiS" userLabel="Save">
+                                    <barButtonItem title="title" id="LlY-NF-IiS" userLabel="Save">
                                         <connections>
                                             <action selector="saveButtonTapped:" destination="J6p-g8-CHO" id="oZp-Hv-neh"/>
                                         </connections>

+ 80 - 3
Picker/DocumentPickerViewController.swift

@@ -23,7 +23,7 @@
 
 import UIKit
 
-class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCNetworkingDelegate, OCNetworkingDelegate {
+class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCNetworkingDelegate, OCNetworkingDelegate, BKPasscodeViewControllerDelegate {
     
     // MARK: - Properties
     
@@ -59,6 +59,9 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     var thumbnailInLoading = [String: IndexPath]()
     var destinationURL : URL?
     
+    var failedAttempts : UInt?
+    var lockUntilDate : Date?
+    
     lazy var networkingOperationQueue : OperationQueue = {
         
         var queue = OperationQueue()
@@ -73,7 +76,6 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     // MARK: - IBOutlets
     
     @IBOutlet weak var tableView: UITableView!
-    
     @IBOutlet weak var toolBar: UIToolbar!
     @IBOutlet weak var saveButton: UIBarButtonItem!
     
@@ -134,6 +136,15 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
         readFolder()
     }
     
+    override func viewWillAppear(_ animated: Bool) {
+        
+        super.viewWillAppear(animated)
+        
+        if CCUtility.getBlockCode().characters.count > 0 && CCUtility.getOnlyLockDir() == false {
+            openBKPasscode()
+        }
+    }
+    
     // MARK: - Overridden Instance Methods
     
     override func prepareForPresentation(in mode: UIDocumentPickerMode) {
@@ -431,7 +442,7 @@ extension DocumentPickerViewController {
             
             self.destinationURL = appGroupContainerURL()?.appendingPathComponent(fileName)
             
-            // copy sourceURL on DirectoryUser
+            // copy sourceURL on directoryUser
             do {
                 try FileManager.default.removeItem(at: destinationURLDirectoryUser)
             } catch _ {
@@ -506,6 +517,72 @@ extension DocumentPickerViewController {
         
         return storagePathUrl
     }
+    
+    func openBKPasscode() {
+        
+        let viewController = CCBKPasscode.init()
+        
+        viewController.delegate = self
+        viewController.type = BKPasscodeViewControllerCheckPasscodeType
+        viewController.inputViewTitlePassword = true
+        
+        if CCUtility.getSimplyBlockCode() {
+            
+            viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle
+            viewController.passcodeInputView.maximumLength = 6
+            
+        } else {
+            
+            viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle
+            viewController.passcodeInputView.maximumLength = 64
+        }
+        
+        let touchIDManager = BKTouchIDManager.init(keychainServiceName: BKPasscodeKeychainServiceName)
+        touchIDManager?.promptText = NSLocalizedString("_scan_fingerprint_", comment: "")
+        viewController.touchIDManager = touchIDManager
+        
+#if CC
+        viewController.title = "Crypto Cloud"
+#endif
+
+#if NC
+        viewController.title = "Nextcloud"
+#endif
+        
+        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(passcodeViewCloseButtonPressed(sender:)))
+        viewController.navigationItem.leftBarButtonItem?.tintColor = UIColor(colorLiteralRed: 241.0/255.0, green: 90.0/255.0, blue: 34.0/255.0, alpha: 1.0) // COLOR_ENCRYPTED
+        
+        let navController = UINavigationController.init(rootViewController: viewController)
+        self.present(navController, animated: true, completion: nil)
+    }
+
+    func passcodeViewControllerNumber(ofFailedAttempts aViewController: BKPasscodeViewController!) -> UInt {
+        return 0
+    }
+    
+    func passcodeViewControllerLock(untilDate aViewController: BKPasscodeViewController!) -> Date! {
+        return nil
+    }
+    
+    func passcodeViewCloseButtonPressed(sender :Any) {
+        dismiss(animated: true, completion: {
+            self.dismissGrantingAccess(to: nil)
+        })
+    }
+    
+    func passcodeViewController(_ aViewController: BKPasscodeViewController!, authenticatePasscode aPasscode: String!, resultHandler aResultHandler: ((Bool) -> Void)!) {
+        if aPasscode == CCUtility.getBlockCode() {
+            lockUntilDate = nil
+            failedAttempts = 0
+            aResultHandler(true)
+        } else {
+            aResultHandler(false)
+        }
+    }
+    
+    public func passcodeViewController(_ aViewController: BKPasscodeViewController!, didFinishWithPasscode aPasscode: String!) {
+        aViewController.dismiss(animated: true, completion: nil)
+    }
 }
 
 // MARK: - UITableViewDelegate

+ 2 - 0
Picker/Picker-Bridging-Header.h

@@ -9,3 +9,5 @@
 #import "CCCoreData.h"
 #import "CCGlobal.h"
 #import "CCHud.h"
+#import "BKPasscodeViewController.h"
+#import "CCBKPasscode.h"