<commit_before>/*

User Model
@author <NAME>

@dependencies:
  mongoose, bcrypt, auth, validate

@usage:
  var User = require('./model');

  // Create a new user
  var user = new User({
    email: ...,
    password: ...,
    ...
  });

  // Protect a route
  app.get('/', User.Auth(), function (req, res) {});

  // Admins only
  app.get('/admin', User.Auth([User.ADMIN]), function (req, res) {});

*/

var mongoose = require('mongoose');
var redis = require('redis').createClient();
var bcrypt = require('bcrypt');
var uuid = require('uuid');
var schema = require('validate');

var User = mongoose.model('User', {
  email: {type: String, unique: true},
  role: {type: String, enum: ['attendee', 'staff', 'admin'], default: 'attendee'},

  application: {type: mongoose.Schema.Types.ObjectId, ref: 'Application'},
  created: {type : Date, default: Date.now},

  password: String,
  salt: String,

  tokens: [{
    client: String,
    token: String,
    refresh: String,
    expires: Date
  }]
});

var Helpers = {

  /**
  * Generate a random salt
  * @return A salt of length 10
  */
  salt: function () {
    return bcrypt.genSaltSync(10);
  },

  /**
  * Hash a password
  * @param password A password
  * @param salt A salt for the algorithm
  * @return The hashed password
  */
  hash: function(password, salt) {
    return bcrypt.hashSync(password, salt);
  },

  /**
  * Generate a token
  * @return A new token
  */
  token: function () {
    return uuid.v4();
  },

  /**
  * Generate an expiration date for a token (3 days from now)
  */
  expires: function () {
    return Date.now() + (3 * (1000 * 60 * 60 * 24));
  },

  /**<commit_msg>Change token expiration to 30 days<commit_after>/*

User Model
@author <NAME>

@dependencies:
  mongoose, bcrypt, auth, validate

@usage:
  var User = require('./model');

  // Create a new user
  var user = new User({
    email: ...,
    password: ...,
    ...
  });

  // Protect a route
  app.get('/', User.Auth(), function (req, res) {});

  // Admins only
  app.get('/admin', User.Auth([User.ADMIN]), function (req, res) {});

*/

var mongoose = require('mongoose');
var redis = require('redis').createClient();
var bcrypt = require('bcrypt');
var uuid = require('uuid');
var schema = require('validate');

var User = mongoose.model('User', {
  email: {type: String, unique: true},
  role: {type: String, enum: ['attendee', 'staff', 'admin'], default: 'attendee'},

  application: {type: mongoose.Schema.Types.ObjectId, ref: 'Application'},
  created: {type : Date, default: Date.now},

  password: String,
  salt: String,

  tokens: [{
    client: String,
    token: String,
    refresh: String,
    expires: Date
  }]
});

var Helpers = {

  /**
  * Generate a random salt
  * @return A salt of length 10
  */
  salt: function () {
    return bcrypt.genSaltSync(10);
  },

  /**
  * Hash a password
  * @param password A password
  * @param salt A salt for the algorithm
  * @return The hashed password
  */
  hash: function(password, salt) {
    return bcrypt.hashSync(password, salt);
  },

  /**
  * Generate a token
  * @return A new token
  */
  token: function () {
    return uuid.v4();
  },

  /**
  * Generate an expiration date for a token (30 days from now)
  */
  expires: function () {
    return Date.now() + (30 * (1000 * 60 * 60 * 24));
  },

  /**
{'fraction_non_alphanumeric': 0.17234106658632117, 'fraction_numerical': 0.011449231696294065, 'mean_word_length': 2.9618138424821003, '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': '611244', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1099, 'n_words': 335}