<commit_before>var errors = require('./replies/en.js').errors;
var has    = require('./util').has;


exports.networkServices = function(next, nick, target) {
  if (has(this.options.networkServices, target.toLowerCase())) {
    next(errors.networkServices, target);
  } else {
    next();
  }
};


exports.isRegistered = function(next, nick, target) {
  this.store.isRegistered(target, function(err, registered) {
    if (err) {
      next(err.message);
    } else if (!registered) {
      next(errors.notRegistered, target);
    /*
    } else if (!verified) {
      next(errors.awaitingVerification);
    */
    } else {
      next();
    }
  });
};


exports.amRegistered = function(next, nick) {
  exports.isRegistered.call(this, next, null, nick);
};


var emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
exports.checkEmail = function(next, nick, password, email) {
  if (emailRegexp.test(email)) {
    next();
  } else {
    next(errors.invalidEmail);
  }
};


exports.tooManyAccounts = function(next, nick, password, email) {
  var max = this.options.maxAccounts;
  if (max === 0) {
    return next();
  }

  this.store.getNumOfAccounts(email, function(err, n) {
    if (err) {
      next(err.message);
    } else if (n > max) {
      next(errors.tooManyAccounts, email);
    } else {
      next();
    }
  });
};


exports.alreadyRegistered = function(next, nick) {
  this.store.isRegistered(nick, function(err, registered) {
    if (err) {
      next(err.message);
    } else if (registered) {
      next(errors.alreadyRegistered, nick);
    } else {
      next();
    }
  });
};


exports.tooSoon = function(next, nick) {
  var min = this.options.minBeforeRegister;
  if (min === 0) {
    return next();
  }

  this.store.getConnectedTime(nick, function(err, time) {
    if (err) {
      next(err.message);
    } else if ((Date.now() - time) / 1000 < min) {
      next(errors.tooSoon, min, 'minute' + (min === 1 ? '' : 's'));
    } else {
      next();
    }
  });
};


exports.accessDenied = function(next, nick, target) {
  if (nick !== target && !has(this.options.ops, nick)) {
    next(errors.accessDenied);
  } else {
    next();
  }
};


exports.notAwaitingAuthorization = function(next, nick, op, target) {
  this.store.isRegistered(nick, function(err, registered, verified) {
    if (err) {
      next(err.message);
    } else if (!registered) {
      next(errors.notRegistered, nick);

    } else if (verified) {
      next(errors.notAwaiting, target);

    } else {
      next();
    }
  });
};


exports.isIdentified = function(next, nick) {
  this.store.isIdentified(nick, function(err, identified) {
    if (err) {
      next(err.message);
    } else if (identified) {
      next();
    } else {
      next(errors.notIdentified);
    }
  });
};
<commit_msg>toLowerCase() is not needed<commit_after>var errors = require('./replies/en.js').errors;
var has    = require('./util').has;


exports.networkServices = function(next, nick, target) {
  if (has(this.options.networkServices, target)) {
    next(errors.networkServices, target);
  } else {
    next();
  }
};


exports.isRegistered = function(next, nick, target) {
  this.store.isRegistered(target, function(err, registered) {
    if (err) {
      next(err.message);
    } else if (!registered) {
      next(errors.notRegistered, target);
    /*
    } else if (!verified) {
      next(errors.awaitingVerification);
    */
    } else {
      next();
    }
  });
};


exports.amRegistered = function(next, nick) {
  exports.isRegistered.call(this, next, null, nick);
};


var emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
exports.checkEmail = function(next, nick, password, email) {
  if (emailRegexp.test(email)) {
    next();
  } else {
    next(errors.invalidEmail);
  }
};


exports.tooManyAccounts = function(next, nick, password, email) {
  var max = this.options.maxAccounts;
  if (max === 0) {
    return next();
  }

  this.store.getNumOfAccounts(email, function(err, n) {
    if (err) {
      next(err.message);
    } else if (n > max) {
      next(errors.tooManyAccounts, email);
    } else {
      next();
    }
  });
};


exports.alreadyRegistered = function(next, nick) {
  this.store.isRegistered(nick, function(err, registered) {
    if (err) {
      next(err.message);
    } else if (registered) {
      next(errors.alreadyRegistered, nick);
    } else {
      next();
    }
  });
};


exports.tooSoon = function(next, nick) {
  var min = this.options.minBeforeRegister;
  if (min === 0) {
    return next();
  }

  this.store.getConnectedTime(nick, function(err, time) {
    if (err) {
      next(err.message);
    } else if ((Date.now() - time) / 1000 < min) {
      next(errors.tooSoon, min, 'minute' + (min === 1 ? '' : 's'));
    } else {
      next();
    }
  });
};


exports.accessDenied = function(next, nick, target) {
  if (nick !== target && !has(this.options.ops, nick)) {
    next(errors.accessDenied);
  } else {
    next();
  }
};


exports.notAwaitingAuthorization = function(next, nick, op, target) {
  this.store.isRegistered(nick, function(err, registered, verified) {
    if (err) {
      next(err.message);
    } else if (!registered) {
      next(errors.notRegistered, nick);

    } else if (verified) {
      next(errors.notAwaiting, target);

    } else {
      next();
    }
  });
};


exports.isIdentified = function(next, nick) {
  this.store.isIdentified(nick, function(err, identified) {
    if (err) {
      next(err.message);
    } else if (identified) {
      next();
    } else {
      next(errors.notIdentified);
    }
  });
};

{'fraction_non_alphanumeric': 0.17449784791965567, 'fraction_numerical': 0.004662840746054519, 'mean_word_length': 2.83826565726084, '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': '5477707', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1924, 'n_words': 369}