<commit_before>/**
 * Created by davis on 3/21/15.
 */
Accounts.registerLoginHandler(function(loginRequest) {
  if (!loginRequest.username || !loginRequest.password)
    return undefined;
  return createFromDalton(loginRequest.username, loginRequest.password);
});

function createFromDalton(username, password) {
  var result = validateUser(username, password);
  if (!result.error) {
    var userId = null;
    var user = Meteor.users.findOne({username: result.username.toLowerCase()});
    if (!user) {
      userId = Accounts.createUser({
        username: result.username.toLowerCase(),
        profile: {
          email: result.email.toLowerCase(),
          fullname: result.fullname,
          grade: result.description
        }
      });
      if (result.groups.indexOf('Students') >= 0) {
        Roles.addUsersToRoles(userId, 'student');
      } else {
        Roles.addUsersToRoles(userId, 'faculty');
      }
      if (_.contains(["c17dh", "c15mb", "cforster"], result.username.toLowerCase())) {
        Roles.addUsersToRoles(userId, 'admin');
      }
    } else {
      userId = user._id;
    }
    var stampedToken = Accounts._generateStampedLoginToken();
    var hashStampedToken = Accounts._hashStampedToken(stampedToken);
    Meteor.users.update(userId, {$push: {'services.resume.loginTokens': hashStampedToken}});
    return {userId: userId, token: stampedToken.token};
  } else {
    return {error: new Meteor.Error(403, 'Incorrect password')};
  }
}

Accounts.createFromDalton = createFromDalton;

Accounts.createUser = function(options) {
  try {
    check(options, Match.ObjectIncluding({
      username: String,
      profile: Match.ObjectIncluding({
        email: String,<commit_msg>fixed 500 error when logging in<commit_after>/**
 * Created by davis on 3/21/15.
 */
Accounts.registerLoginHandler(function(loginRequest) {
  if (!loginRequest.username || !loginRequest.password)
    return undefined;
  return createFromDalton(loginRequest.username, loginRequest.password);
});

function createFromDalton(username, password) {
  var result = validateUser(username, password);
  if (!result.error) {
    var userId = null;
    var user = Meteor.users.findOne({username: result.username.toLowerCase()});
    if (!user) {
      userId = Accounts.createUser({
        username: result.username.toLowerCase(),
        profile: {
          email: result.email.toLowerCase(),
          fullname: result.fullname,
          grade: parseInt(result.description)
        }
      });
      if (result.groups.indexOf('Students') >= 0) {
        Roles.addUsersToRoles(userId, 'student');
      } else {
        Roles.addUsersToRoles(userId, 'faculty');
      }
      if (_.contains(["c17dh", "c15mb", "cforster"], result.username.toLowerCase())) {
        Roles.addUsersToRoles(userId, 'admin');
      }
    } else {
      userId = user._id;
    }
    var stampedToken = Accounts._generateStampedLoginToken();
    var hashStampedToken = Accounts._hashStampedToken(stampedToken);
    Meteor.users.update(userId, {$push: {'services.resume.loginTokens': hashStampedToken}});
    return {userId: userId, token: stampedToken.token};
  } else {
    return {error: new Meteor.Error(403, 'Incorrect password')};
  }
}

Accounts.createFromDalton = createFromDalton;

Accounts.createUser = function(options) {
  try {
    check(options, Match.ObjectIncluding({
      username: String,
      profile: Match.ObjectIncluding({
        email: String,
{'fraction_non_alphanumeric': 0.1327536231884058, 'fraction_numerical': 0.008405797101449276, 'mean_word_length': 3.4130434782608696, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2682980', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1059, 'n_words': 198}