<commit_before>var bcrypt = require( 'bcrypt' );
var appModels = require( '../models' );
var systemError = require( '../utils/error_messages' ).systemError;


exports.isEmailInUse = function ( email, callback ) {

    appModels.User.findOne( { email: email }, function ( err, user ) {

        if ( err ) {
            return callback( systemError( err ) );
        }

        if ( user ) {
            return callback( null, true );
        }

        return callback( null, false );

    } );

};


exports.createUser = function ( email, password, callback ) {

    var newUserData = {
        email: email,
        password: <PASSWORD>.hashSync( password, 8 ),
        role: "user"
    };

    appModels.User.create( newUserData, function ( err, newUser ) {

        if ( err ) {
            return callback( systemError( err ) );
        }

        return callback( null, newUser );

    } );

};<commit_msg>Add custom conflict error response<commit_after>var bcrypt = require( 'bcrypt' );
var appModels = require( '../models' );
var systemError = require( '../utils/error_messages' ).systemError;
var conflictError = require( '../utils/error_messages' ).conflictError;


exports.isEmailInUse = function ( email, callback ) {

    appModels.User.findOne( { email: email }, function ( err, user ) {

        if ( err ) {
            return callback( systemError( err ) );
        }

        if ( user ) {
            return callback( null, true );
        }

        return callback( null, false );

    } );

};


exports.createUser = function ( email, password, callback ) {

    var newUserData = {
        email: email,
        password: <PASSWORD>.hashSync( password, 8 ),
        role: "user"
    };

    appModels.User.create( newUserData, function ( err, newUser ) {

        if ( err ) {
            if ( err.code === 11000 ) {
                return callback( conflictError( "Email address is in use" ) );
            }
            return callback( systemError( err ) );
        }

        return callback( null, newUser );

    } );

};
{'fraction_non_alphanumeric': 0.13170731707317074, 'fraction_numerical': 0.0034146341463414634, 'mean_word_length': 2.0657698056801195, 'pattern_counts': {'":': 0, '<': 5, '<?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': '762326', 'n_tokens_mistral': 599, 'n_tokens_neox': 567, 'n_words': 158}