<commit_before>var _ = require('lodash')
  , _s = require('underscore.string')
  , async = require('async')
  , validator = require('validator/validator-min')
  , check = validator.check
  , sanitize = validator.sanitize;

exports.create = function (model, dom) {
  var root = model.parent().parent()
    , config = root.at(model.get('config') || '$user')
    , form = this.form = dom.element(model.get('form') || 'form')
    , username = this.username = dom.element(model.get('username') || 'username')
    , email = this.username = dom.element(model.get('email') || 'email')
    , password = this.password = dom.element(model.get('password') || 'password');

  var form = this.form = dom.element(model.get('form') || 'form');
  if (!$) require('../../vendor/jquery.min.js');
  if (!$.fn.ajaxForm) require('../../vendor/jquery.form.min.js');
  if (!$.fn.popupWindow) require('../../vendor/jquery.popupWindow.min.js');
  if (!form) return console.error('must specifiy form element (i.e. <form x-as="form">...</form>');

  var validateEmail = function (e, callback) {
    var value = _s.trim(email.value)
      , $validation = model.at(email).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
      }
    }

    if (value.length > config.get('validation.email.maximumLength')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '2');
      return callback(true);
    }

    if (value.length < config.get('validation.email.minimumLength')) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '3');
      }
      return callback(true);
    }

    try {
      check(value).isEmail();
    } catch (ex) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '4');
      }
      return callback(true);
    }

    $.ajax({
      data: {
        user: {
          public: {
            local: {username: value}
          },
          private: {
            local: {email: value}
          }
        }
      },
      type: 'POST',
      url: '/userExists'
    }).done(function (data) {
      if (data.exists) {
        if (e.type === 'keyup') {
          $validation.set('state', 'tolerated');
          $validation.del('code');
        } else {
          $validation.set('state', 'invalid');
          $validation.set('code', '5');
        }
        return callback(true);
      } else {
        $validation.set('state', 'valid');
        $validation.del('code');
        callback();
      }
    });
  };

  var validatePassword = function (e, callback) {
    var value = password.value
      , $validation = model.at(password).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
      }
      return callback(true);
    }

    if (value.length < config.get('validation.password.minimumLength')) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '2');
      }
      return callback(true);
    }

    if (value.length > config.get('validation.password.maximumLength')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '3');
      return callback(true);
    }

    $validation.set('state', 'valid');
    $validation.del('code');
    callback();
  };

  var validateUsername = function (e, callback) {
    var value = _s.trim(username.value)
      , $validation = model.at(username).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
      }
    }

    if (_s.contains(value, ' ')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '2');
      return callback(true);
    }

    var invalid = value.match(/[^a-zA-Z0-9_-]/);
<commit_msg>return after required validation fails on username/email<commit_after>var _ = require('lodash')
  , _s = require('underscore.string')
  , async = require('async')
  , validator = require('validator/validator-min')
  , check = validator.check
  , sanitize = validator.sanitize;

exports.create = function (model, dom) {
  var root = model.parent().parent()
    , config = root.at(model.get('config') || '$user')
    , form = this.form = dom.element(model.get('form') || 'form')
    , username = this.username = dom.element(model.get('username') || 'username')
    , email = this.username = dom.element(model.get('email') || 'email')
    , password = this.password = dom.element(model.get('password') || 'password');

  var form = this.form = dom.element(model.get('form') || 'form');
  if (!$) require('../../vendor/jquery.min.js');
  if (!$.fn.ajaxForm) require('../../vendor/jquery.form.min.js');
  if (!$.fn.popupWindow) require('../../vendor/jquery.popupWindow.min.js');
  if (!form) return console.error('must specifiy form element (i.e. <form x-as="form">...</form>');

  var validateEmail = function (e, callback) {
    var value = _s.trim(email.value)
      , $validation = model.at(email).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
        return callback(true);
      }
    }

    if (value.length > config.get('validation.email.maximumLength')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '2');
      return callback(true);
    }

    if (value.length < config.get('validation.email.minimumLength')) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '3');
      }
      return callback(true);
    }

    try {
      check(value).isEmail();
    } catch (ex) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '4');
      }
      return callback(true);
    }

    $.ajax({
      data: {
        user: {
          public: {
            local: {username: value}
          },
          private: {
            local: {email: value}
          }
        }
      },
      type: 'POST',
      url: '/userExists'
    }).done(function (data) {
      if (data.exists) {
        if (e.type === 'keyup') {
          $validation.set('state', 'tolerated');
          $validation.del('code');
        } else {
          $validation.set('state', 'invalid');
          $validation.set('code', '5');
        }
        return callback(true);
      } else {
        $validation.set('state', 'valid');
        $validation.del('code');
        callback();
      }
    });
  };

  var validatePassword = function (e, callback) {
    var value = password.value
      , $validation = model.at(password).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
      }
      return callback(true);
    }

    if (value.length < config.get('validation.password.minimumLength')) {
      if (e.type === 'keyup') {
        $validation.set('state', 'tolerated');
        $validation.del('code');
      } else {
        $validation.set('state', 'invalid');
        $validation.set('code', '2');
      }
      return callback(true);
    }

    if (value.length > config.get('validation.password.maximumLength')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '3');
      return callback(true);
    }

    $validation.set('state', 'valid');
    $validation.del('code');
    callback();
  };

  var validateUsername = function (e, callback) {
    var value = _s.trim(username.value)
      , $validation = model.at(username).at('validation')
      , callback = callback || function () {};

    if (!value) {
      if (e.type === 'submit') {
        $validation.set('state', 'invalid');
        $validation.set('code', '1');
      } else {
        $validation.set('state', 'default');
        $validation.del('code');
        return callback(true);
      }
    }

    if (_s.contains(value, ' ')) {
      $validation.set('state', 'invalid');
      $validation.set('code', '2');
      return callback(true);
    }

    var invalid = value.match(/[^a-zA-Z0-9_-]/);

{'fraction_non_alphanumeric': 0.19949308269088606, 'fraction_numerical': 0.002534586545569754, 'mean_word_length': 2.3967001434720228, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2336836', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2856, 'n_words': 530}