This commit is contained in:
2022-01-02 22:07:03 -03:00
parent 0232b1dcf1
commit edd044b742
32 changed files with 11579 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
'use strict'
const bcrypt = require('bcrypt-nodejs');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const UsuarioSchema = Schema({
nombre: String,
mail: String,
pass: String,
activo: Boolean
});
UsuarioSchema.pre('save', function(next) {
const usuario = this;
if (!usuario.isModified('pass')) {
return next();
}
if (usuario.activo == null) {
usuario.activo = false;
}
bcrypt.genSalt(10, (err, salt) => {
if (err) {
next(err);
}
bcrypt.hash(usuario.pass, salt, null, (err, hash) => {
if (err) {
next(err);
}
usuario.pass = hash;
next();
});
})
})
module.exports = mongoose.model('usuario', UsuarioSchema);