<commit_before>//
// Created by <NAME> on 05/09/15.
// Copyright (c) 2015 <NAME>. All rights reserved.
//

import Alamofire
import UIKit
import vincerp

private let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"

extension UITextField {
   
    var isValidEmail: Bool {
        return definedAs {
            let range = self.reactiveText.value().rangeOfString(emailRegEx, options:.RegularExpressionSearch)
            return range != nil
        }*
    }

    var isValidPassword: Bool {
        return definedAs {
            self.reactiveText*.trim().length > 0
        }*
    }
    
}

class LoginViewControler: UIViewController {
    
    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var passwordField: UITextField!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
    
    override func viewDidAppear(animated: Bool) {
        setupLoginButtonUI()
        
        self.loginButton.reactiveEnabled = definedAs {
            self.emailField.isValidEmail &&
            self.passwordField.isValidPassword
        }

        self.emailField.text = "<EMAIL>"
        self.passwordField.text = "<PASSWORD>"

        self.activityIndicator.reactiveHidden = self.loginButton.executing.not()
        self.loginButton.reactiveHidden = self.loginButton.executing
        
        let alert = reactive("")
        alert.onChange(true) {
            let message = $0
            let alertController = UIAlertController(title: "Login Result",
                message: message,
                preferredStyle: UIAlertControllerStyle.Alert)
            
            alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))
            self.presentViewController(alertController, animated: true, completion: nil)
        }
        
        self.loginButton.clickHandler = definedAs { i in
            let loginService = LoginService()
            loginService.login(self.emailField.text!, password: self.passwordField.text!).onChange { _ in
                alert <- "Login was successfull!"<commit_msg>Close keyboard on login<commit_after>//
// Created by <NAME> on 05/09/15.
// Copyright (c) 2015 <NAME>. All rights reserved.
//

import Alamofire
import UIKit
import vincerp

private let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"

extension UITextField {
   
    var isValidEmail: Bool {
        return definedAs {
            let range = self.reactiveText.value().rangeOfString(emailRegEx, options:.RegularExpressionSearch)
            return range != nil
        }*
    }

    var isValidPassword: Bool {
        return definedAs {
            self.reactiveText*.trim().length > 0
        }*
    }
    
}

class LoginViewControler: UIViewController {
    
    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var passwordField: UITextField!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
    
    override func viewDidAppear(animated: Bool) {
        setupLoginButtonUI()
        
        self.loginButton.reactiveEnabled = definedAs {
            self.emailField.isValidEmail &&
            self.passwordField.isValidPassword
        }

        self.emailField.text = "<EMAIL>"
        self.passwordField.text = "<PASSWORD>"

        self.activityIndicator.reactiveHidden = self.loginButton.executing.not()
        self.loginButton.reactiveHidden = self.loginButton.executing
        
        let alert = reactive("")
        alert.onChange(true) {
            let message = $0
            let alertController = UIAlertController(title: "Login Result",
                message: message,
                preferredStyle: UIAlertControllerStyle.Alert)
            
            alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))
            self.presentViewController(alertController, animated: true, completion: nil)
        }
        
        self.loginButton.clickHandler = definedAs { i in
            self.emailField.resignFirstResponder()
            self.passwordField.resignFirstResponder()
            let loginService = LoginService()
            loginService.login(self.emailField.text!, password: self.passwordField.text!).onChange { _ in
                alert <- "Login was successfull!"
{'fraction_non_alphanumeric': 0.09906839354692115, 'fraction_numerical': 0.008634401272438082, 'mean_word_length': 2.3861538461538463, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1215735', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1203, 'n_words': 256}