<commit_before>/**
 * User service
 */
var User = require('mongoose').model('User');
var encrypt = require('../utils/encryption');
var mailer = require('../utils/mailer');
var validator = require('validator');

/**
 * Return array of all users
 */
exports.getUsers = function(req, res, next) {
  User.find({}).exec(function(err, collection) {
    if (err) {
      return next(err);
    }
    res.send(collection);
    return collection;
  });
};

/**
 * Return the user with the given id
 */
exports.getUserById = function(req, res, next) {
  User.findOne({_id: req.params.id}).exec(function(err, user) {
    if (err) {
      return next(err);
    }
    user.populateUser().then(function() {
      res.send(user);
    });
  });
};

/**
 * Create a new user
 */
exports.createUser = function(req, res, next) {
  // Get the user data from the request
  var userData = req.body;

  // Encrypt password
  userData.salt = encrypt.createSalt();
  if (req.session.facebookId || req.session.twitterId || req.session.googleId) { // If registration from social network
    console.log('test');
    userData.password = encrypt.createToken();
  }
  if (userData.password) {
    userData.hashedPassword = encrypt.hashPassword(userData.salt, userData.password);
  }
  if (req.session.facebookId) {
    userData.facebookId = req.session.facebookId;
  }
  if (req.session.twitterId) {
    userData.twitterId = req.session.twitterId;
  }
  if (req.session.googleId) {
    userData.googleId = req.session.googleId;
  }
  // Validate data
  var validationErrorMessage = User.validate(userData);
  if (validationErrorMessage) {
    return next(new Error(validationErrorMessage));
  }

  // Create user
  User.create(userData, function(err, user) {
    if (err) {<commit_msg>Remove console log debug<commit_after>/**
 * User service
 */
var User = require('mongoose').model('User');
var encrypt = require('../utils/encryption');
var mailer = require('../utils/mailer');
var validator = require('validator');

/**
 * Return array of all users
 */
exports.getUsers = function(req, res, next) {
  User.find({}).exec(function(err, collection) {
    if (err) {
      return next(err);
    }
    res.send(collection);
    return collection;
  });
};

/**
 * Return the user with the given id
 */
exports.getUserById = function(req, res, next) {
  User.findOne({_id: req.params.id}).exec(function(err, user) {
    if (err) {
      return next(err);
    }
    user.populateUser().then(function() {
      res.send(user);
    });
  });
};

/**
 * Create a new user
 */
exports.createUser = function(req, res, next) {
  // Get the user data from the request
  var userData = req.body;

  // Encrypt password
  userData.salt = encrypt.createSalt();
  if (req.session.facebookId || req.session.twitterId || req.session.googleId) { // If registration from social network
    userData.password = encrypt.createToken();
  }
  if (userData.password) {
    userData.hashedPassword = encrypt.hashPassword(userData.salt, userData.password);
  }
  if (req.session.facebookId) {
    userData.facebookId = req.session.facebookId;
  }
  if (req.session.twitterId) {
    userData.twitterId = req.session.twitterId;
  }
  if (req.session.googleId) {
    userData.googleId = req.session.googleId;
  }
  // Validate data
  var validationErrorMessage = User.validate(userData);
  if (validationErrorMessage) {
    return next(new Error(validationErrorMessage));
  }

  // Create user
  User.create(userData, function(err, user) {
    if (err) {
{'fraction_non_alphanumeric': 0.15283342873497424, 'fraction_numerical': 0.0, 'mean_word_length': 3.39070351758794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1532936', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1117, 'n_words': 244}