2
I am unable to encrypt my password during an update using bcrypt in Mongoose. The password is changed smoothly but without encryption.
Follow the schema:
var mongoose= require('mongoose');
module.exports= function(){
var schema= mongoose.Schema({
email:{
type: String,
required: true
},
senha:{
type: String,
required: true,
bcrypt: true
},
});
schema.plugin(require('mongoose-bcrypt'));
return mongoose.model('Usuario', schema);}
Follows excerpt from the controller:
controller.updateUsuario= function(req, res){
var Usuario= app.models.usuario;
var _id= req.params.id;
// Atualização de cadastro
if(_id){
Usuario.findByIdAndUpdate(_id, req.body).exec()
.then(
function(usuario){
res.json(usuario);
},
function(erro){
console.error(erro);
res.status(500).json(erro);
}
);
}};