<commit_before>var mongoose = require('mongoose');
var passportLocalMongoose = require('passport-local-mongoose');
var sha1 = require('sha1');

var Schema = mongoose.Schema;

var userSchema = new Schema({
    email: String,
    resetPasswordToken: String,
    confirmMailToken: String,
    emailConfirmed: Boolean,
    roles: [Schema.Types.ObjectId],
    fields: {}
}, {collection: 'bauhaus-users'});


userSchema.methods.setResetPasswordToken = function () {
    var time = Date.now().toString();
    var token = sha1( time + this.email + this.username );
    this.resetPasswordToken = token;
};

userSchema.methods.setConfirmMailToken = function () {
    var time = Date.now().toString();
    var token = sha1( time + this.email + this.username );
    this.confirmMailToken = token;
};

userSchema.plugin(passportLocalMongoose);

var user = module.exports = mongoose.model('User', userSchema); <commit_msg>Avoid exposition of user hash and salt at REST endpoints<commit_after>var mongoose = require('mongoose');
var passportLocalMongoose = require('passport-local-mongoose');
var sha1 = require('sha1');

var Schema = mongoose.Schema;

var userSchema = new Schema({
    email: String,
    resetPasswordToken: String,
    confirmMailToken: String,
    emailConfirmed: Boolean,
    roles: [Schema.Types.ObjectId],
    fields: {}
}, {collection: 'bauhaus-users'});


userSchema.methods.setResetPasswordToken = function () {
    var time = Date.now().toString();
    var token = sha1( time + this.email + this.username );
    this.resetPasswordToken = token;
};

userSchema.methods.setConfirmMailToken = function () {
    var time = Date.now().toString();
    var token = sha1( time + this.email + this.username );
    this.confirmMailToken = token;
};

userSchema.methods.toJSON = function() {
    var user = this.toObject();
    delete user.salt;
    delete user.hash;
    return user;
};

userSchema.plugin(passportLocalMongoose);

var user = module.exports = mongoose.model('User', userSchema); 
{'fraction_non_alphanumeric': 0.13319979969954931, 'fraction_numerical': 0.00400600901352028, 'mean_word_length': 4.216710182767624, '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': '2094481', 'n_tokens_mistral': 600, 'n_tokens_neox': 605, 'n_words': 142}