<commit_before>var uuid = require('node-uuid');
var bcrypt = require('bcrypt');

var msg = require('../msg');

var orm = require('../../../database.js');
var Subscriber = orm['subscribers'];
var Session = orm['sessions'];
// var mailer = require('../../mailer');

// ----------------------------------------------------------------------------
// Subscriber

Array.prototype.containsEmail = function(email) {
   for (i in this) {
       if (this[i].email == email) return true;
   }
   return false;
}

function insertSubscriber(em, pwd, ip, cb){
  var token = uuid.v4();
  var encrypted = bcrypt.hashSync(pwd, 10); // encrypt the password
  if (Subscriber.containsEmail(em)) {
    cb(msg.emailInUse());
  } else {
    var subToAdd = {
      email: em,
      password: <PASSWORD>,
      reg_date: new Date(),
      reg_ip: ip, 
      verification_token: token,
      status: 'CREATED'
    };
    Subscriber.push(subToAdd);
    var newSub = Subscriber[Subscriber.length-1];
    if (newSub == subToAdd) {
      cb(msg.success(newSub));
    } else {
      cb(msg.unknownError(Subscriber.pop()));
    };
  }
}

// ----------------------------------------------------------------------------
// Testing insert subscriber

// should return success
insertSubscriber('testemail', 'iluvflowg', '127.0.0.1', 
  function(result) {
    console.log(result);
  });

// should return emailInUse error
insertSubscriber('testemail', 'testpassword', '127.0.0.1', 
  function(result) {
    console.log(result);
  });

console.log(Subscriber);
console.log(bcrypt.compareSync('<PASSWORD>', Subscriber[0].password))
// ----------------------------------------------------------------------------

function sendVerificationEmail(em, cb){
cb(msg.success());
}

exports.insertSubscriber = insertSubscriber;
exports.sendVerificationEmail = sendVerificationEmail;
<commit_msg>slightly changed formatting in testAdapter<commit_after>var uuid = require('node-uuid');
var bcrypt = require('bcrypt');

var msg = require('../msg');

var orm = require('../../../database.js');
var Subscriber = orm['subscribers'];
var Session = orm['sessions'];
// var mailer = require('../../mailer');

// ----------------------------------------------------------------------------
// Subscriber

Array.prototype.containsEmail = function(email) {
   for (i in this) {
       if (this[i].email == email) return true;
   }
   return false;
}

function insertSubscriber(em, pwd, ip, cb){
  var token = uuid.v4();
  var encrypted = bcrypt.hashSync(pwd, 10); // encrypt the password
  if (Subscriber.containsEmail(em)) {
    cb(msg.emailInUse());
  } else {
    var subToAdd = {
      email: em,
      password: <PASSWORD>,
      reg_date: new Date(),
      reg_ip: ip, 
      verification_token: token,
      status: 'CREATED'
    };
    Subscriber.push(subToAdd);
    var newSub = Subscriber[Subscriber.length-1];
    if (newSub == subToAdd) {
      cb(msg.success(newSub));
    } else {
      cb(msg.unknownError(Subscriber.pop()));
    };
  }
}

// ----------------------------------------------------------------------------
// Testing insert subscriber
console.log("inserting a test subscriber returns:\n");
// should return success
insertSubscriber('testemail', 'iluvflowg', '127.0.0.1', 
  function(result) {
    console.log(result);
  });

console.log("\ninserting another one with the same email:\n");
// should return emailInUse error
insertSubscriber('testemail', 'testpassword', '127.0.0.1', 
  function(result) {
    console.log(result);
  });
console.log("\nthe full subscriber array:\n");
console.log(Subscriber);
console.log("\ncomparing the encrypted password to iluvflowg:\n");
console.log(bcrypt.compareSync('<PASSWORD>', Subscriber[0].password));
// ----------------------------------------------------------------------------

function sendVerificationEmail(em, cb){
cb(msg.success());
}

exports.insertSubscriber = insertSubscriber;
exports.sendVerificationEmail = sendVerificationEmail;


{'fraction_non_alphanumeric': 0.2616822429906542, 'fraction_numerical': 0.008588027279616064, 'mean_word_length': 2.2646331409727947, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '6015316', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1143, 'n_words': 246}