<commit_before>
/*
  define models
*/

var User = require('../models/db').User;
var Forms = require('../models/forms');

/*
  define shared server vars
*/

var io = require('../server').io;

/*
  define shared controllers
*/

var que = require('../lib/que');
var form = require('../lib/forms');
var inject = require('../lib/shot');
var token = require('../lib/hash');

/*
 * GET users listing.
 */

exports.list = function (req, res) {
  User.find(function (err, users) {
    res.send(users);
  });
};

/*
 * POST users listing.
 */

exports.add = function (req, res) {
  console.log(req.body);
  token.make(req.body.hash, function (err, salted, hashed) {

    if (err) {
      console.log('err');
      console.log(err);
    }

    var user = new User({
      username : req.body.username,
      hash: hashed,
      first_name: req.body.first_name || null,
      last_name: req.body.last_name || null,
      email: req.body.email
    });

    user.created = new Date();
    user.save(function (err) {
      if (!err) {
        req.session.messages = 'created';
        res.redirect('/');
      } else {
        console.log(err);
        req.session.messages = 'error';
        res.redirect('/register');
      }
    });
  });
};

/*
 * Registration page controller
 */

exports.register = function (req, res) {

  //get shorter reference of register form model
  var register = Forms.register;

  //render our form from the model<commit_msg>still an issue with scope somewhere<commit_after>
/*
  define models
*/

var User = require('../models/db').User;
var Forms = require('../models/forms');

/*
  define shared server vars
*/

var io = require('../server').io;

/*
  define shared controllers
*/

var que = require('../lib/que');
var form = require('../lib/forms');
var inject = require('../lib/shot');
var token = require('../lib/hash');

/*
 * GET users listing.
 */

exports.list = function (req, res) {
  User.find(function (err, users) {
    res.send(users);
  });
};

/*
 * POST users listing.
 */

exports.add = function (req, res) {
  console.log(req.body);
  token.make(req.body.hash, function (err, salted, hashed) {

    if (err) {
      console.log('err');
      console.log(err);
    }

    var user = new User({
      username : req.body.username,
      hash: hashed,
      first_name: req.body.first_name || null,
      last_name: req.body.last_name || null,
      email: req.body.email
    });
    user.save(function (err) {
      if (!err) {
        req.session.messages = 'created';
        res.redirect('/');
      } else {
        console.log(err);
        req.session.messages = 'error';
        res.redirect('/register');
      }
    });
  });
};

/*
 * Registration page controller
 */

exports.register = function (req, res) {

  //get shorter reference of register form model
  var register = Forms.register;

  //render our form from the model
{'fraction_non_alphanumeric': 0.17501739735560196, 'fraction_numerical': 0.0, 'mean_word_length': 2.4555288461538463, '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': '6300929', 'n_tokens_mistral': 937, 'n_tokens_neox': 916, 'n_words': 227}