<commit_before>//
//  FirstViewController.swift
//  LocalAuthenticationExamples
//
//  Created by <NAME> on 24/07/2014.
//  Copyright (c) 2014 Yetii Ltd. All rights reserved.
//

import UIKit
import AuthenticationManager

class PINViewController: UIViewController, AuthenticationDelegate, PINSetupDelegate, PINUpdateDelegate, PINAuthenticationDelegate {

    var manager: AuthenticationManager = AuthenticationManager.sharedInstance
    @IBOutlet weak var currentCodeLabel: UILabel!
    @IBOutlet weak var setCodeButton: UIButton!
    @IBOutlet weak var updateCodeButton: UIButton!
    @IBOutlet weak var testCodeButton: UIButton!
    @IBOutlet weak var lastTestResultLabel: UILabel!
    @IBOutlet weak var resetPINButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setup the buttons and labels
        self.updateUI()
    }

    func updateUI() {
        if let currentCode = self.manager.userDefaults.stringForKey(kAMPINKey) {
            self.currentCodeLabel.text = "Current PIN: \(currentCode)"
            self.setCodeButton.enabled = false
            self.updateCodeButton.enabled = true
            self.testCodeButton.enabled = true
            self.resetPINButton.enabled = true
        } else {
            // No PIN code has been set yet
            self.currentCodeLabel.text = "Current PIN: Not Set"
            self.setCodeButton.enabled = true
            self.updateCodeButton.enabled = false
            self.testCodeButton.enabled = false
            self.resetPINButton.enabled = false
        }
    }

    /// Button pressed methods

    @IBAction func setCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationSetupViewControllerForType(.PIN) as PINSetupViewController
        viewController.delegate = self
        viewController.setupDelegate = self
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func updateCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationUpdateViewControllerForType(.PIN) as PINUpdateViewController
        viewController.delegate = self
        viewController.updateDelegate = self
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func testCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationViewControllerForType(.PIN) as PINAuthenticationViewController
        viewController.delegate = self
        viewController.authenticationDelegate = self
        let currentPIN = self.manager.userDefaults.stringForKey(kAMPINKey);
        assert(currentPIN != nil, "Cannot test PIN with no PIN set")
        viewController.PIN = currentPIN
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func resetPINButtonWasPressed(sender: UIButton) {
        self.manager.userDefaults.removeObjectForKey(kAMPINKey)
        self.manager.userDefaults.synchronize()
        self.updateUI()
    }

    /// AuthenticationDelegate methods

    func authenticationWasCanceled(viewController: AuthenticationViewController) {
        if viewController is PINAuthenticationViewController {
            self.lastTestResultLabel.text = "Last Result: Canceled"
        }
    }

    /// PINSetupDelegate methods

    func setupCompleteWithPIN(PIN: String) {
        // Save the PIN to the user defaults
        self.manager.userDefaults.setValue(PIN, forKey: kAMPINKey)
        self.manager.userDefaults.synchronize()
        // Remove the popup view
        self.dismissViewControllerAnimated(true, completion: nil)
        // Update the UI
        self.updateUI()
    }

    /// PINModifyDelegate methods

    func PINWasUpdated(newPIN: String) {
        self.dismissViewControllerAnimated(true, completion: nil)
        // Update the UI
        self.updateUI()
    }

    /// PINAuthenticationDelegate methods

    func authenticationDidSucceed() {
        self.lastTestResultLabel.text = "Last Result: Authenticated"
        self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }<commit_msg>Removed some pieces code now present in the framework<commit_after>//
//  FirstViewController.swift
//  LocalAuthenticationExamples
//
//  Created by <NAME> on 24/07/2014.
//  Copyright (c) 2014 Yetii Ltd. All rights reserved.
//

import UIKit
import AuthenticationManager

class PINViewController: UIViewController, AuthenticationDelegate, PINSetupDelegate, PINUpdateDelegate, PINAuthenticationDelegate {

    var manager: AuthenticationManager = AuthenticationManager.sharedInstance
    @IBOutlet weak var currentCodeLabel: UILabel!
    @IBOutlet weak var setCodeButton: UIButton!
    @IBOutlet weak var updateCodeButton: UIButton!
    @IBOutlet weak var testCodeButton: UIButton!
    @IBOutlet weak var lastTestResultLabel: UILabel!
    @IBOutlet weak var resetPINButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setup the buttons and labels
        self.updateUI()
    }

    func updateUI() {
        if let currentCode = self.manager.userDefaults.stringForKey(kAMPINKey) {
            self.currentCodeLabel.text = "Current PIN: \(currentCode)"
            self.setCodeButton.enabled = false
            self.updateCodeButton.enabled = true
            self.testCodeButton.enabled = true
            self.resetPINButton.enabled = true
        } else {
            // No PIN code has been set yet
            self.currentCodeLabel.text = "Current PIN: Not Set"
            self.setCodeButton.enabled = true
            self.updateCodeButton.enabled = false
            self.testCodeButton.enabled = false
            self.resetPINButton.enabled = false
        }
    }

    /// Button pressed methods

    @IBAction func setCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationSetupViewControllerForType(.PIN) as PINSetupViewController
        viewController.delegate = self
        viewController.setupDelegate = self
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func updateCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationUpdateViewControllerForType(.PIN) as PINUpdateViewController
        viewController.delegate = self
        viewController.updateDelegate = self
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func testCodeButtonWasPressed(sender: UIButton) {
        let viewController = self.manager.getAuthenticationViewControllerForType(.PIN) as PINAuthenticationViewController
        viewController.delegate = self
        viewController.authenticationDelegate = self
        self.presentViewController(viewController.viewInNavigationController(), animated: true, completion: nil)
    }

    @IBAction func resetPINButtonWasPressed(sender: UIButton) {
        self.manager.userDefaults.removeObjectForKey(kAMPINKey)
        self.manager.userDefaults.synchronize()
        self.updateUI()
    }

    /// AuthenticationDelegate methods

    func authenticationWasCanceled(viewController: AuthenticationViewController) {
        if viewController is PINAuthenticationViewController {
            self.lastTestResultLabel.text = "Last Result: Canceled"
        }
    }

    /// PINSetupDelegate methods

    func setupCompleteWithPIN(PIN: String) {
        // Remove the popup view
        self.dismissViewControllerAnimated(true, completion: nil)
        // Update the UI
        self.updateUI()
    }

    /// PINModifyDelegate methods

    func PINWasUpdated(newPIN: String) {
        self.dismissViewControllerAnimated(true, completion: nil)
        // Update the UI
        self.updateUI()
    }

    /// PINAuthenticationDelegate methods

    func authenticationDidSucceed() {
        self.lastTestResultLabel.text = "Last Result: Authenticated"
        self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
{'fraction_non_alphanumeric': 0.07484558556376408, 'fraction_numerical': 0.0029066246820879252, 'mean_word_length': 3.129, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686210', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2020, 'n_words': 486}