<commit_before>// app/models/user.js
// load the things we need
var mongoose = require('mongoose');
var bcrypt   = require('bcrypt-nodejs');

// define the schema for our user model
var userSchema = mongoose.Schema({

    local            : {
        email        : String,
        password     : String,
    },
    facebook         : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    },
    twitter          : {
        id           : String,
        token        : String,
        displayName  : String,
        username     : String
    },
    google           : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    }

});

// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
};


// we will use .pre to hash our password before saving our user
// we don't have to manually create our hash
// we are hashing asynchronously so we are not blocking our application when multiple people are signing up
userSchema.pre('save', function(next) {
    var user = this;

    // hash the password
    bcrypt.hash(user.local.password, null, null, function(err, hash) {
        if (err)
            return next(err);

        console.log(user.local.password);
        console.log(hash);

        user.local.password = hash;
        next();
    });

});

// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);<commit_msg>Update user.js<commit_after>// app/models/user.js
// load the things we need
var mongoose = require('mongoose');
var bcrypt   = require('bcrypt-nodejs');

// define the schema for our user model
var userSchema = mongoose.Schema({

    local            : {
        email        : String,
        password     : String,
    },
    facebook         : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    },
    twitter          : {
        id           : String,
        token        : String,
        displayName  : String,
        username     : String
    },
    google           : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    }

});

// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
};


// we will use .pre to hash our password before saving our user
// we don't have to manually create our hash
// we are hashing asynchronously so we are not blocking our application when multiple people are signing up
userSchema.pre('save', function(next) {
    var user = this;

    // hash the password
    bcrypt.hash(user.local.password, null, null, function(err, hash) {
        if (err)
            return next(err);

        user.local.password = <PASSWORD>;
        next();
    });

});

// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);

{'fraction_non_alphanumeric': 0.09730913642052566, 'fraction_numerical': 0.0, 'mean_word_length': 1.744206008583691, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1411217', 'n_tokens_mistral': 856, 'n_tokens_neox': 846, 'n_words': 278}