<commit_before>module.exports = (function(){
    'use strict';

    var mongoose = require('mongoose'),
        validate = require('mongoose-validator').validate,
        _ = require('underscore'),
        crypto = require('../../../utils/crypto'),
        Schema = mongoose.Schema,
        ObjectId = Schema.ObjectId,
        nodeSchema = new Schema({
            nodeid : { type: ObjectId },
            role: {type : String }
        },{ _id: false }),
        schema = new Schema({
            firstname : { type: String, trim: true, required: true },
            lastname : { type: String, trim: true, required: true },
            email : { type : String, required : true, lowercase: true, trim: true},
            role : { type : String, required : true, default: 'reader' },
            login : {
                type : String,
                required : true,
                trim: true,
                index : {
                    unique : true
                },
                validate: validate('len', 4)
            },
            pass_hash : { type : String, required : true },
            salt      : { type : String, required : true },
            profile : {},
            permissions : [nodeSchema],
            enabled : { type: Boolean, default: true },
            dateCreated : { type: Date, default: Date.now }
        });


    schema.virtual('password').set(function (password) {
        if(password && password.length >= 6){
            this.salt = crypto.createSalt();
            this.pass_hash = crypto.createHash(password, this.salt);
        }
    });

    schema.path('role').validate(function (value) {
        var roles = ['editor', 'author', 'reader', 'admin', 'none', 'external'],
            foundRole = _.findWhere(roles, value);

        return (foundRole !== null);
    }, 'Invalid role.');

    schema.virtual('password').get(function () {
        return this.pass_hash;
    });

    schema.methods.authenticate = function (plaintext) {
        return (crypto.createHash(plaintext, this.salt) == this.password && this.enabled);
    };

    return schema;
})();<commit_msg>Added in some nicer error messages.<commit_after>module.exports = (function(){
    'use strict';

    var mongoose = require('mongoose'),
        validate = require('mongoose-validator').validate,
        _ = require('underscore'),
        crypto = require('../../../utils/crypto'),
        Strings = require('../../../strings'),
        strings = new Strings(),
        Schema = mongoose.Schema,
        ObjectId = Schema.ObjectId,
        nodeSchema = new Schema({
            nodeid : { type: ObjectId },
            role: {type : String }
        },{ _id: false }),
        schema = new Schema({
            firstname : { type: String, trim: true, required: true },
            lastname : { type: String, trim: true, required: true },
            email : { type : String, required : true, lowercase: true, trim: true},
            role : { type : String, required : true, default: 'reader' },
            login : {
                type : String,
                required : true,
                trim: true,
                index : {
                    unique : true
                },
                validate: validate({message: strings.group('errors').login_too_short},'len', 4)
            },
            pass_hash : {
                type : String,
                required : [true, 'Password must be at least 6 characters.']
            },
            salt      : {
                type : String,
                required : [true, 'Password must be at least 6 characters.']
            },
            profile : {},
            permissions : [nodeSchema],
            enabled : { type: Boolean, default: true },
            dateCreated : { type: Date, default: Date.now }
        });


    schema.virtual('password').set(function (password) {
        if(password && password.length >= 6){
            this.salt = crypto.createSalt();
            this.pass_hash = crypto.createHash(password, this.salt);
        }
    });

    schema.path('role').validate(function (value) {
        var roles = ['editor', 'author', 'reader', 'admin', 'none', 'external'],
            foundRole = _.findWhere(roles, value);

        return (_.isString(foundRole));
    }, 'User\'s role is invalid.');

    schema.virtual('password').get(function () {
        return this.pass_hash;
    });

    schema.methods.authenticate = function (plaintext) {
        return (crypto.createHash(plaintext, this.salt) == this.password && this.enabled);
    };

    return schema;
})();
{'fraction_non_alphanumeric': 0.14282594452937322, 'fraction_numerical': 0.001310329766324525, 'mean_word_length': 1.7723970944309928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6621235', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1166, 'n_words': 300}