<commit_before>'use strict';

/**
* @fileOverview User Model Declaration
* @author <a href="mailto:<EMAIL>"><NAME></a>
*/


/*
 * Module dependencies.
 */
var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
	crypto = require('crypto'),
	serverJSON = require('../../local_files/ui/server.ui.json'),
	async = require('async'),
	PrivateFunctions = require('./_privateFunctions'),
	Helper = require('../../custom_objects/Helper');

/*
 * A Validation function for local strategy properties
 */
var validateLocalStrategyProperty = function(property) {
	return ((this.provider !== 'local' && !this.updated) || property.length);
};

var validateLocalStrategyPhoneNumber = function(number) {
	return (this.provider !== 'local' || number.toString().length >= 10);
};

/*
 * A Validation function for local strategy password
 */
var validateLocalStrategyPassword = function(password) {
	return (this.provider !== 'local' || (password && password.length > 6));
};

function isValidObjectIDs(ids) {

	console.log('addedByIDS: ' + ids);
	if(!Helper.isValidObjectIDs(ids))
	{
		console.log('failed');
		return false;
	}

	return true;
}

function isUniqueArray(ids) {
	
	if(!Helper.isUniqueArray(ids))
		return false;

	return true;
}

/**
	*	@class User
	*	@property {string} firstName
	*	@property {string} lastName
	*	@property {string} displayName
	*	@property {string} email
	*	@property {string} carrier
	*	@property {number} phoneNumber
	*	@property {string} username
	*	@property {string} password
	*	@property {Group[]} createdGroups
	*	@property {Group[]} joinedGroups
	*	@property {string} salt
	*	@property {string} provider
	*	@property {object} providerData
	*	@property {string} additionalProvidersData
	*	@property {string} roles enum: ['user','admin'] default: 'user'
	*	@property {date} updated
	*	@property {date} created
	*	@property {string} resetPasswordToken
	*	@property {date} resetPasswordExpires
 */

var UserSchema = new Schema({
	firstName: {
		type: String,
		trim: true,
		required: 'firstName.empty',
		match: [new RegExp(serverJSON.api.users.firstName.invalid.regex), 'firstName.invalid']
	},
	lastName: {
		type: String,
		trim: true,
		required: 'lastName.empty',
		match: [new RegExp(serverJSON.api.users.lastName.invalid.regex), 'lastName.invalid']
	},
	displayName: {
		type: String,
		trim: true
	},
	email: {
		type: String,
		trim: true,
		default: '',
		match: [new RegExp(serverJSON.api.users.email.invalid.regex), 'email.invalid']
	},
	carrier: {
		type: String,
		trim: true,
		default: '',
	},
	phoneNumber: {
		type: Number,
		default: -1,
		match: [new RegExp(serverJSON.api.users.phoneNumber.invalid.regex), 'phoneNumber.invalid']
	},
	username: {
		type: String,
		unique: 'testing error message',
		required: 'username.empty',
		match: [new RegExp(serverJSON.api.users.username.invalid.regex), 'username.invalid'],
		trim: true
	},
	password: {
		type: String
	},
	plainTextPassword: {
		type: String,
		default: '',
		required: 'plainTextPassword.empty',
		match: [new RegExp(serverJSON.api.users.plainTextPassword.invalid.regex), 'plainTextPassword.invalid']
	},
	createdGroups: {
		type: [Schema.ObjectId],
		ref: 'Group',
		validate: 
		[
			{
				validator: Helper.isValidObjectIDs,
				msg: 'createdGroups.invalid'
			},
			{
				validator: Helper.isUniqueArray,
				msg: 'createdGroups.duplicate'
			}
		]
	},
	joinedGroups: {
		type: [Schema.ObjectId],
		ref: 'Group',<commit_msg>removed required field on plainTextPassword<commit_after>'use strict';

/**
* @fileOverview User Model Declaration
* @author <a href="mailto:<EMAIL>"><NAME></a>
*/


/*
 * Module dependencies.
 */
var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
	crypto = require('crypto'),
	serverJSON = require('../../local_files/ui/server.ui.json'),
	async = require('async'),
	PrivateFunctions = require('./_privateFunctions'),
	Helper = require('../../custom_objects/Helper');

/*
 * A Validation function for local strategy properties
 */
var validateLocalStrategyProperty = function(property) {
	return ((this.provider !== 'local' && !this.updated) || property.length);
};

var validateLocalStrategyPhoneNumber = function(number) {
	return (this.provider !== 'local' || number.toString().length >= 10);
};

/*
 * A Validation function for local strategy password
 */
var validateLocalStrategyPassword = function(password) {
	return (this.provider !== 'local' || (password && password.length > 6));
};

function isValidObjectIDs(ids) {

	console.log('addedByIDS: ' + ids);
	if(!Helper.isValidObjectIDs(ids))
	{
		console.log('failed');
		return false;
	}

	return true;
}

function isUniqueArray(ids) {
	
	if(!Helper.isUniqueArray(ids))
		return false;

	return true;
}

/**
	*	@class User
	*	@property {string} firstName
	*	@property {string} lastName
	*	@property {string} displayName
	*	@property {string} email
	*	@property {string} carrier
	*	@property {number} phoneNumber
	*	@property {string} username
	*	@property {string} password
	*	@property {Group[]} createdGroups
	*	@property {Group[]} joinedGroups
	*	@property {string} salt
	*	@property {string} provider
	*	@property {object} providerData
	*	@property {string} additionalProvidersData
	*	@property {string} roles enum: ['user','admin'] default: 'user'
	*	@property {date} updated
	*	@property {date} created
	*	@property {string} resetPasswordToken
	*	@property {date} resetPasswordExpires
 */

var UserSchema = new Schema({
	firstName: {
		type: String,
		trim: true,
		required: 'firstName.empty',
		match: [new RegExp(serverJSON.api.users.firstName.invalid.regex), 'firstName.invalid']
	},
	lastName: {
		type: String,
		trim: true,
		required: 'lastName.empty',
		match: [new RegExp(serverJSON.api.users.lastName.invalid.regex), 'lastName.invalid']
	},
	displayName: {
		type: String,
		trim: true
	},
	email: {
		type: String,
		trim: true,
		default: '',
		match: [new RegExp(serverJSON.api.users.email.invalid.regex), 'email.invalid']
	},
	carrier: {
		type: String,
		trim: true,
		default: '',
	},
	phoneNumber: {
		type: Number,
		default: -1,
		match: [new RegExp(serverJSON.api.users.phoneNumber.invalid.regex), 'phoneNumber.invalid']
	},
	username: {
		type: String,
		unique: 'testing error message',
		required: 'username.empty',
		match: [new RegExp(serverJSON.api.users.username.invalid.regex), 'username.invalid'],
		trim: true
	},
	password: {
		type: String
	},
	plainTextPassword: {
		type: String,
		default: '',
		match: [new RegExp(serverJSON.api.users.plainTextPassword.invalid.regex), 'plainTextPassword.invalid']
	},
	createdGroups: {
		type: [Schema.ObjectId],
		ref: 'Group',
		validate: 
		[
			{
				validator: Helper.isValidObjectIDs,
				msg: 'createdGroups.invalid'
			},
			{
				validator: Helper.isUniqueArray,
				msg: 'createdGroups.duplicate'
			}
		]
	},
	joinedGroups: {
		type: [Schema.ObjectId],
		ref: 'Group',
{'fraction_non_alphanumeric': 0.1583855456797319, 'fraction_numerical': 0.0011656709893632523, 'mean_word_length': 4.482428115015974, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7042433', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2266, 'n_words': 497}