<commit_before>var mongoose = require('mongoose');
var async = require('async');
var database_server = 'mongodb://localhost/test'; // It actually dynamic depends on where the server is (in case you host it with OpenShift)
mongoose.connect(database_server);

// State of the art
module.exports.is_connected = false;

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
//db.once('open', function() {
    module.exports.is_connected = true;
	var userSchema = new mongoose.Schema({
		user_id: String,
		password: String,
		certificate: String
	});
	var User = mongoose.model('User',userSchema);

	module.exports.registerUser = function(data, fn, fn_error) {
		var user = new User({
			user_id: data['user_id'],
			password: data['password'],
			certificate: data['certificate']
		});
		user.save(function (err, user) {
			if (err) fn_error();
            else fn();
		});
	};

	module.exports.checkUser = function(data, fn) {
        User.findOne({'user_id': data['user_id'], 'password': data['password']}, function(err, User) {
			if (err) fn(false);
            else {
                if(User != null) fn(true);
                else fn(false);
            };
        });
	};

	module.exports.getUser = function(user_id, fn, fn_error) {
		User.findOne( {'user_id' : user_id}, function (err, User) {
			if (err) fn_error();
            else {
                if(User == null) fn_error();
                else fn(User);
            };
		});
	};
<commit_msg>model.js: Add implementation when user name already taken<commit_after>var mongoose = require('mongoose');
var async = require('async');
var database_server = 'mongodb://localhost/test'; // It actually dynamic depends on where the server is (in case you host it with OpenShift)
mongoose.connect(database_server);

// State of the art
module.exports.is_connected = false;

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
//db.once('open', function() {
    module.exports.is_connected = true;
	var userSchema = new mongoose.Schema({
		user_id: String,
		password: String,
		certificate: String
	});
	var User = mongoose.model('User',userSchema);

	module.exports.registerUser = function(data, fn, fn_error) {
		var user = new User({
			user_id: data['user_id'],
			password: data['password'],
			certificate: data['certificate']
		});

        // Check if user is actually exist
        module.exports.getUser(data['user_id'], function() {
            // The user exist, return error
            fn_error();
        }, function() {
            // The user doesn't exist, add it to database
            user.save(function (err, user) {
                if (err) fn_error();
                else fn();
            });
        })
	};

	module.exports.checkUser = function(data, fn) {
        User.findOne({'user_id': data['user_id'], 'password': data['password']}, function(err, User) {
			if (err) fn(false);
            else {
                if(User != null) fn(true);
                else fn(false);
            };
        });
	};

	module.exports.getUser = function(user_id, fn, fn_error) {
		User.findOne( {'user_id' : user_id}, function (err, User) {
			if (err) fn_error();
            else {
                if(User == null) fn_error();
                else fn(User);
            };
		});
	};

{'fraction_non_alphanumeric': 0.15085303801257108, 'fraction_numerical': 0.0, 'mean_word_length': 2.700996677740864, 'pattern_counts': {'":': 0, '<': 3, '<?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': '150905', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1016, 'n_words': 260}