
var config = require('tresdb-config');
var db = require('tresdb-db');
var bcrypt = require('bcryptjs');

exports.createUser = function (username, email, password, callback) {
  // Create non-admin active user. Does not check if user exists.
  //
  // Parameters:
  //   username
  //     string
  //   email
  //     string
  //   password
  //     string
  //   callback
  //     function (err)

  var users = db.collection('users');

  var r = config.bcrypt.rounds;

  bcrypt.hash(password, r, function (berr, pwdHash) {

    if (berr) {
      return callback(berr);
    }

    users.insert({
      name: username,
      email: email,
      hash: pwdHash,
      admin: false,
      status: 'active',  // 'deactivated'
    }, function (qerr) {

      if (qerr) {
        return callback(qerr);
      }

      // User inserted successfully
      return callback();
    });
  });
};


var config = require('tresdb-config');
var db = require('tresdb-db');
var bcrypt = require('bcryptjs');

exports.createUser = function (username, email, password, callback) {
  // Create non-admin active user. Does not check if user exists.
  //
  // Parameters:
  //   username
  //     string
  //   email
  //     string
  //   password
  //     string
  //   callback
  //     function (err)

  var users = db.collection('users');

  var r = config.bcrypt.rounds;

  bcrypt.hash(password, r, function (berr, pwdHash) {
    if (berr) {
      return callback(berr);
    }

    users.insert({
      name: username,
      email: email,
      hash: pwdHash,
      admin: false,
      status: 'active',  // options. 'active' | 'deactivated',
      createdAt: (new Date()).toISOString(),
      loginAt: (new Date()).toISOString(),
    }, function (qerr) {
      if (qerr) {
        return callback(qerr);
      }
      // User inserted successfully
      return callback();
    });
  });
};

Create new users with createdAt and loginAt props
Create new users with createdAt and loginAt props
