<commit_before>/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

import UIKit
import Parse

class ViewController: UIViewController {

    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var password: UITextField!
    @IBOutlet weak var driverToggle: UISwitch!

    var indicator = UIActivityIndicatorView()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    @IBAction func signupPressed(sender: AnyObject) {
        let user = PFUser()

        if checkEntries() {
            displaySpinner()

            user.username = username.text
            user.password = <PASSWORD>
            user["isDriver"] = driverToggle.on

            user.signUpInBackgroundWithBlock({
                (success, error) -> Void in

                self.indicator.stopAnimating()
                UIApplication.sharedApplication().endIgnoringInteractionEvents()

                if success {
                    // Nothing for now
                }
                else {
                    var errorMsg = "please try again later"

                    if let errorStr = error?.userInfo["error"] as? String {
                        errorMsg = errorStr
                    }

                    self.displayAlert(errorMsg, title: "There was a problem signing up")
                }
            })
        }

    }

    @IBAction func loginPressed(sender: AnyObject) {
        if checkEntries() {
            displaySpinner()

            PFUser.logInWithUsernameInBackground(username.text!, password: <PASSWORD>!, block: { (user, error) -> Void in

                self.indicator.stopAnimating()
                UIApplication.sharedApplication().endIgnoringInteractionEvents()

                if error == nil {
                    // Nothing for now
                }
                else {
                    var errorMsg = "please try again later"

                    if let errorStr = error?.userInfo["error"] as? String {
                        errorMsg = errorStr
                    }

                    self.displayAlert(errorMsg, title: "There was a problem logging in")
                }
            })
        }
    }

    func checkEntries() -> Bool {
        if username.text == "" || password.text == "" {
            displayAlert("You must enter both a username and password", title: "There was a problem")
            return false
        }

        return true
    }

    func displayAlert(message: String, title: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)

        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
            self.dismissViewControllerAnimated(true, completion: nil)
        }))

        self.presentViewController(alert, animated: true, completion: nil)
    }

    func displaySpinner() {
        indicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
        indicator.center = self.view.center
        indicator.hidesWhenStopped = true
        indicator.activityIndicatorViewStyle = .Gray

        self.view.addSubview(indicator)

        indicator.startAnimating()
        UIApplication.sharedApplication().beginIgnoringInteractionEvents()
    }





    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
<commit_msg>Add code to close the keyboard on click or return<commit_after>/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

import UIKit
import Parse

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var password: UITextField!
    @IBOutlet weak var driverToggle: UISwitch!

    var indicator = UIActivityIndicatorView()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.username.delegate = self
        self.password.delegate = self
    }

    @IBAction func signupPressed(sender: AnyObject) {
        let user = PFUser()

        if checkEntries() {
            displaySpinner()

            user.username = username.text
            user.password = password.<PASSWORD>
            user["isDriver"] = driverToggle.on

            user.signUpInBackgroundWithBlock({
                (success, error) -> Void in

                self.indicator.stopAnimating()
                UIApplication.sharedApplication().endIgnoringInteractionEvents()

                if success {
                    // Nothing for now
                }
                else {
                    var errorMsg = "please try again later"

                    if let errorStr = error?.userInfo["error"] as? String {
                        errorMsg = errorStr
                    }

                    self.displayAlert(errorMsg, title: "There was a problem signing up")
                }
            })
        }

    }

    @IBAction func loginPressed(sender: AnyObject) {
        if checkEntries() {
            displaySpinner()

            PFUser.logInWithUsernameInBackground(username.text!, password: <PASSWORD>!, block: { (user, error) -> Void in

                self.indicator.stopAnimating()
                UIApplication.sharedApplication().endIgnoringInteractionEvents()

                if error == nil {
                    // Nothing for now
                }
                else {
                    var errorMsg = "please try again later"

                    if let errorStr = error?.userInfo["error"] as? String {
                        errorMsg = errorStr
                    }

                    self.displayAlert(errorMsg, title: "There was a problem logging in")
                }
            })
        }
    }

    func checkEntries() -> Bool {
        if username.text == "" || password.text == "" {
            displayAlert("You must enter both a username and password", title: "There was a problem")
            return false
        }

        return true
    }

    func displayAlert(message: String, title: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)

        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
            self.dismissViewControllerAnimated(true, completion: nil)
        }))

        self.presentViewController(alert, animated: true, completion: nil)
    }

    func displaySpinner() {
        indicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50))
        indicator.center = self.view.center
        indicator.hidesWhenStopped = true
        indicator.activityIndicatorViewStyle = .Gray

        self.view.addSubview(indicator)

        indicator.startAnimating()
        UIApplication.sharedApplication().beginIgnoringInteractionEvents()
    }

    // Clicking outside the text fields will close the keyboard

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.view.endEditing(true)
    }

    // Pressing return will close the keyboard
    
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()

        return true
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

{'fraction_non_alphanumeric': 0.08390367553865653, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 1.921510551647538, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 17, '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': '6425576', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1915, 'n_words': 566}