<commit_before>/**
 *  class models.users.TokenActivationEmail
 *
 *  Expirable secret key used for email address confirmation by newly
 *  registered users.
 **/


'use strict';


var Mongoose = require('mongoose');
var Schema   = Mongoose.Schema;
var crypto   = require('crypto');


var TOKEN_EXPIRE_TIMEOUT    = 6 * 60 * 60; // 6 hours.
var TOKEN_SECRET_KEY_LENGTH = 16;


function generateSecretKey() {
  return crypto.randomBytes(TOKEN_SECRET_KEY_LENGTH).toString('hex');
}


module.exports = function (N, collectionName) {
  var TokenActivationEmail = new Schema({
    secret_key : { type: String,                'default': generateSecretKey   }
  , email      : { type: String,                required: true                 }
  , create_ts  : { type: Date,                  expires:  TOKEN_EXPIRE_TIMEOUT }
  });

  TokenActivationEmail.statics.generateSecretKey = generateSecretKey;

  TokenActivationEmail.methods.isExpired = function isExpired() {
    return Date.now() >= (this.create_ts.getTime() + TOKEN_EXPIRE_TIMEOUT);
  };

  TokenActivationEmail.index({ user_id: 1 }, { unique: true });


  N.wire.on("init:models", function emit_init_TokenActivationEmail(__, callback) {
    N.wire.emit("init:models." + collectionName, TokenActivationEmail, callback);
  });

  N.wire.on("init:models." + collectionName, function init_model_TokenActivationEmail(schema) {
    N.models[collectionName] = Mongoose.model(collectionName, schema);
  });<commit_msg>Fix index on TokenActivationEmail collection.<commit_after>/**
 *  class models.users.TokenActivationEmail
 *
 *  Expirable secret key used for email address confirmation by newly
 *  registered users.
 **/


'use strict';


var Mongoose = require('mongoose');
var Schema   = Mongoose.Schema;
var crypto   = require('crypto');


var TOKEN_EXPIRE_TIMEOUT    = 6 * 60 * 60; // 6 hours.
var TOKEN_SECRET_KEY_LENGTH = 16;


function generateSecretKey() {
  return crypto.randomBytes(TOKEN_SECRET_KEY_LENGTH).toString('hex');
}


module.exports = function (N, collectionName) {
  var TokenActivationEmail = new Schema({
    secret_key : { type: String,                'default': generateSecretKey   }
  , email      : { type: String,                required: true                 }
  , create_ts  : { type: Date,                  expires:  TOKEN_EXPIRE_TIMEOUT }
  });

  TokenActivationEmail.statics.generateSecretKey = generateSecretKey;

  TokenActivationEmail.methods.isExpired = function isExpired() {
    return Date.now() >= (this.create_ts.getTime() + TOKEN_EXPIRE_TIMEOUT);
  };

  TokenActivationEmail.index({ secret_key: 1 }, { unique: true });


  N.wire.on("init:models", function emit_init_TokenActivationEmail(__, callback) {
    N.wire.emit("init:models." + collectionName, TokenActivationEmail, callback);
  });

  N.wire.on("init:models." + collectionName, function init_model_TokenActivationEmail(schema) {
    N.models[collectionName] = Mongoose.model(collectionName, schema);
  });
{'fraction_non_alphanumeric': 0.11929705981750592, 'fraction_numerical': 0.006083136194660358, 'mean_word_length': 3.6984126984126986, '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': '2215687', 'n_tokens_mistral': 934, 'n_tokens_neox': 893, 'n_words': 188}