<commit_before>var db = require('../../config/sequelize');
var md5 = require('MD5');
var moment = require('moment');
var async = require('async');
var validator = require('validator');
var mailer = require('../lib/mailer');
var _ = require('lodash');
var config = require('../../config/config');
var braintree = require('../lib/braintree');
var paypal = require('../../config/paypal');

exports.users_index = function(req, res) {
	db.User.scope('not_deleted').findAll()
		.success(function(users) {
			return res.send({
				code: 'OK',
				users: users
			});
		})
		.error(function(err) {
			console.log(err);
			return res.status(401).send({ 
		        error: 'Unexpected error occured.',
		        code: 'UNEXPECTED_ERROR'
		      });
		});
};

exports.users_create = function(req, res) {
	if(!req.body.type) {
		return res.status(400).send({ 
			error: 'Please select user type.',
			code: 'EMPTY_TYPE'
		});
	}
	if(req.body.type != 'ADMIN' && req.body.type != 'SRS' && req.body.type != 'DRIVER') {
		return res.status(400).send({ 
			error: 'Invalid user type.',
			code: 'INVALID_TYPE'
		});
	}
	if(!req.body.firstname) {
		if(req.body.type == 'SRS') {
			return res.status(400).send({ 
				error: 'Please enter business name.',
				code: 'EMPTY_BUSINESSNAME'
			});
		}
		else {
			return res.status(400).send({ 
				error: 'Please enter first name.',
				code: 'EMPTY_FIRSTNAME'
			});
		}
	}
	if(req.body.type != 'SRS' && !req.body.lastname) {
		return res.status(400).send({ 
		error: 'Please enter last name.',
		code: 'EMPTY_LASTNAME'
		});
	}
	if(!req.body.email) {
		return res.status(400).send({ 
		error: 'Please enter email address.',
		code: 'EMPTY_EMAIL'
		});
	}
	if(!req.body.password || req.body.password.length < 6) {
		return res.status(400).send({ 
			error: 'Passwords must be at least 6 charactors.',
			code: 'INVALID_PASSWORD'
		}); 
	}

	if(req.body.type == 'SRS' && (!req.body.address || !req.body.latitude || !req.body.longitude)) {
		return res.status(400).send({ 
			error: 'Please enter your address.',
			code: 'EMPTY_ADDRESS'
		}); 
	}

	if(req.body.password) {
		req.body.salt = req.user.makeSalt();
		req.body.hashedPassword = req.user.encryptPassword(req.body.password, req.user.salt);
	}

	req.body.status = 'ACTIVE';

	db.User.create(req.body).success(function(user){
		return res.send({<commit_msg>Hash password issue when creating new user from BAM<commit_after>var db = require('../../config/sequelize');
var md5 = require('MD5');
var moment = require('moment');
var async = require('async');
var validator = require('validator');
var mailer = require('../lib/mailer');
var _ = require('lodash');
var config = require('../../config/config');
var braintree = require('../lib/braintree');
var paypal = require('../../config/paypal');

exports.users_index = function(req, res) {
	db.User.scope('not_deleted').findAll()
		.success(function(users) {
			return res.send({
				code: 'OK',
				users: users
			});
		})
		.error(function(err) {
			console.log(err);
			return res.status(401).send({ 
		        error: 'Unexpected error occured.',
		        code: 'UNEXPECTED_ERROR'
		      });
		});
};

exports.users_create = function(req, res) {
	if(!req.body.type) {
		return res.status(400).send({ 
			error: 'Please select user type.',
			code: 'EMPTY_TYPE'
		});
	}
	if(req.body.type != 'ADMIN' && req.body.type != 'SRS' && req.body.type != 'DRIVER') {
		return res.status(400).send({ 
			error: 'Invalid user type.',
			code: 'INVALID_TYPE'
		});
	}
	if(!req.body.firstname) {
		if(req.body.type == 'SRS') {
			return res.status(400).send({ 
				error: 'Please enter business name.',
				code: 'EMPTY_BUSINESSNAME'
			});
		}
		else {
			return res.status(400).send({ 
				error: 'Please enter first name.',
				code: 'EMPTY_FIRSTNAME'
			});
		}
	}
	if(req.body.type != 'SRS' && !req.body.lastname) {
		return res.status(400).send({ 
		error: 'Please enter last name.',
		code: 'EMPTY_LASTNAME'
		});
	}
	if(!req.body.email) {
		return res.status(400).send({ 
		error: 'Please enter email address.',
		code: 'EMPTY_EMAIL'
		});
	}
	if(!req.body.password || req.body.password.length < 6) {
		return res.status(400).send({ 
			error: 'Passwords must be at least 6 charactors.',
			code: 'INVALID_PASSWORD'
		}); 
	}

	if(req.body.type == 'SRS' && (!req.body.address || !req.body.latitude || !req.body.longitude)) {
		return res.status(400).send({ 
			error: 'Please enter your address.',
			code: 'EMPTY_ADDRESS'
		}); 
	}

	if(req.body.password) {
		req.body.salt = req.user.makeSalt();
		req.body.hashedPassword = req.user.encryptPassword(req.body.password, req.body.salt);
	}

	req.body.status = 'ACTIVE';

	db.User.create(req.body).success(function(user){
		return res.send({
{'fraction_non_alphanumeric': 0.19406779661016949, 'fraction_numerical': 0.013135593220338982, 'mean_word_length': 3.38347260909935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5592927', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1691, 'n_words': 329}