<commit_before>'use strict';

var dynamo = require('dynamodb'),
    Joi    = require('joi'),
    AWS    = dynamo.AWS,
    hashing = require('../lib/userHash')
;
// AWS.config.loadFromPath(process.env.HOME + '/.aws/credentials.json');

module.exports.userSchema = Joi.object().keys({
  email: Joi.string().email().required(),
  password: Joi.string().min(8).max(255).required(),
  firstName: Joi.string().required(),
  lastName: Joi.string().required(),
  phone: Joi.string().optional()  
});


module.exports.dbUser = dynamo.define('users', {
  hashKey : 'userID',
  tableName: 'users',
  timestamps: true,
  schema : {
    userID: dynamo.types.uuid(),
    email: Joi.string().email(),
    password: <PASSWORD>(),
    firstName: Joi.string().optional(),
    lastName: Joi.string().optional(),
    phone: Joi.string().optional()
  }
});

module.exports.create = function(user, callback) {
  hashing.hashUser(user.password, function(err, hash) {
    if (err) {
      return callback(err, null)
    }
    // Set user password = hash
    user.password = <PASSWORD>;
    // Create user
    module.exports.dbUser.create({
      email: user.email.toLowerCase(),
      password: <PASSWORD>,
      firstName: user.firstName,
      lastName: user.lastName
    }, function(err, user) {
      if (err) {
        return callback(err, null);
      } else {
        return callback(null, user)
      } 
    });  
  })
}

module.exports.userExists = function(email, callback) {
  module.exports.dbUser.scan()
  .where('email').equals(email.toLowerCase())
  .exec(function(err, user) {
    if (err) {
      return callback(err, null);
    }

    if (user.Count > 0) {
      return callback(null, true);
    } else {
      return callback(null, false);
    }
  });
}<commit_msg>User registration<commit_after>'use strict';

var dynamo = require('dynamodb'),
    Joi    = require('joi'),
    AWS    = dynamo.AWS,
    hashing = require('../lib/userHash')
;
// AWS.config.loadFromPath(process.env.HOME + '/.aws/credentials.json');


module.exports.userSchema = Joi.object().keys({
  email: Joi.string().email().required(),
  password: Joi.string().min(8).max(255).required(),
  firstName: Joi.string().required(),
  lastName: Joi.string().required(),
  phone: Joi.string().optional()  
});


module.exports.dbUser = dynamo.define('users', {
  hashKey : 'userID',
  tableName: 'users',
  timestamps: true,
  schema : {
    userID: dynamo.types.uuid(),
    email: Joi.string().email(),
    password: Joi.string(),
    firstName: Joi.string().optional(),
    lastName: Joi.string().optional(),
    phone: Joi.string().optional()
  }
});

module.exports.create = function(user, callback) {
  hashing.hashUser(user.password, function(err, hash) {
    if (err) {
      return callback(err, null)
    }
    // Set user password = hash
    user.password = <PASSWORD>;
    // Create user
    module.exports.dbUser.create({
      email: user.email.toLowerCase(),
      password: <PASSWORD>,
      firstName: user.firstName,
      lastName: user.lastName
    }, function(err, user) {
      if (err) {
        return callback(err, null);
      } else {
        return callback(null, user)
      } 
    });  
  })
}

module.exports.userExists = function(email, callback) {
  module.exports.dbUser.scan()
  .where('email').equals(email.toLowerCase())
  .exec(function(err, user) {
    if (err) {
      return callback(err, null);
    }

    if (user.Count > 0) {
      return callback(null, true);
    } else {
      return callback(null, false);
    }
  });
}
{'fraction_non_alphanumeric': 0.1750354609929078, 'fraction_numerical': 0.0028368794326241137, 'mean_word_length': 2.9617977528089887, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '6109091', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1168, 'n_words': 215}