<commit_before>/**
 * User Model Definition
**/
module.exports = function(db) {
  
  var User = db.define('user', {
    number        : { type: 'text', size: 100, required: true },
    status        : { type: 'text', size: 40, defaultValue: 'INACTIVE'},
    rtc_id        : { type: 'text', size: 100 },
    otp_code      : { type: 'text', size: 100 },
    expired       : { type: 'date', time: true },
    code          : { type: 'text', size: 500 }
  }, {
    methods: {
      computeExpiryDate: function(dateObj) {
        var that = this;

        var durationConfig = {};

        var addYear = durationConfig.year || 0,
            addMonth = durationConfig.month || 0,
            addDay = durationConfig.day || 0,
            addHours = durationConfig.hour || 1;


        dateObj.setUTCFullYear(parseInt(dateObj.getUTCFullYear()) + parseInt(addYear));
        dateObj.setMonth(parseInt(dateObj.getMonth()) + parseInt(addMonth));
        dateObj.setDate(parseInt(dateObj.getDate()) + parseInt(addDay));
        dateObj.setHours(parseInt(dateObj.getHours()) + parseInt(addHours));

        return dateObj;
      }
    }
  });
  
  // create table
  User.sync(function(err) {
  
  });
  

  User.generateOTPCode = function(number) {

    var codeLength = 8;
    var crypto = require('crypto');
    
    // get the salt to a config OR create a salt per user
    var salt = '<KEY>';
    
    var d = new Date();

    var cipherSubject = number + d.toUTCString();

    // encrypt password using crypto module (http://nodejs.org/api/crypto.html)
    var cipher = crypto.createCipher('aes-256-cbc', salt);
    var activationCode = cipher.update(cipherSubject, 'utf8', 'hex') + cipher.final('hex');

    // substring the code if it exceeds the maxLength
    // if (activationCode.length > codeLength) {
    //   activationCode = activationCode.substring(90, maxCodeLength);
    // }

    var genCodeLength = activationCode.length;
    activationCode.substring(genCodeLength - 10, genCodeLength); 
 
    return activationCode; 
  }
  
  return User;
}<commit_msg>fixed otp code<commit_after>/**
 * User Model Definition
**/
module.exports = function(db) {
  
  var User = db.define('user', {
    number        : { type: 'text', size: 100, required: true },
    status        : { type: 'text', size: 40, defaultValue: 'INACTIVE'},
    rtc_id        : { type: 'text', size: 100 },
    otp_code      : { type: 'text', size: 100 },
    expired       : { type: 'date', time: true },
    code          : { type: 'text', size: 500 }
  }, {
    methods: {
      computeExpiryDate: function(dateObj) {
        var that = this;

        var durationConfig = {};

        var addYear = durationConfig.year || 0,
            addMonth = durationConfig.month || 0,
            addDay = durationConfig.day || 0,
            addHours = durationConfig.hour || 1;


        dateObj.setUTCFullYear(parseInt(dateObj.getUTCFullYear()) + parseInt(addYear));
        dateObj.setMonth(parseInt(dateObj.getMonth()) + parseInt(addMonth));
        dateObj.setDate(parseInt(dateObj.getDate()) + parseInt(addDay));
        dateObj.setHours(parseInt(dateObj.getHours()) + parseInt(addHours));

        return dateObj;
      }
    }
  });
  
  // create table
  User.sync(function(err) {
  
  });
  

  User.generateOTPCode = function(number) {

    var codeLength = 8;
    var crypto = require('crypto');
    
    // get the salt to a config OR create a salt per user
    var salt = 'c<PASSWORD>';
    
    var d = new Date();

    var cipherSubject = number + d.toUTCString();

    // encrypt password using crypto module (http://nodejs.org/api/crypto.html)
    var cipher = crypto.createCipher('aes-256-cbc', salt);
    var activationCode = cipher.update(cipherSubject, 'utf8', 'hex') + cipher.final('hex');

    // substring the code if it exceeds the maxLength
    // if (activationCode.length > codeLength) {
    //   activationCode = activationCode.substring(90, maxCodeLength);
    // }

    var genCodeLength = activationCode.length;
    activationCode = activationCode.substring(genCodeLength - 10, genCodeLength); 
 
    return activationCode; 
  }
  
  return User;
}
{'fraction_non_alphanumeric': 0.1362759286058852, 'fraction_numerical': 0.013024602026049204, 'mean_word_length': 2.565778159931212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4848791', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1262, 'n_words': 299}