Структура модели базы данных
var crypto = require('crypto');
module.exports = {
models:{
user:{
UserPhoto : {type : String , default : null, extended:true, ignoresave:true, template:"form_image"},
MailCode : {type : String, default : '', trim : true, select:false},
MobilePhone: {type : String, default : '', trim : true, mask:"+7 (999) 999-9999"},
PassHash : {select:false},
PassSalt : {select:false}
}
},
schema: {
user: function(schema){
schema.path('LoginUser').set(function(val){ return (val+'').toLowerCase().trim(); });
schema.path('Mail').set(function(val){ return (val+'').toLowerCase().trim(); });
schema.statics.SearchableFields = function(){
return ["NameUser","CodeUser","LoginUser","JobTitle","Phone","Mail","Comment","CodeObj"];
}
schema.virtual('password')
.set(function(password) {
if (password) {
this._plainPassword = password;
this.PassSalt = Math.random() + '';
this.PassHash = this.encryptPassword(password);
this.DoResetPass = false;
}
})
.get(function() { return this._plainPassword; });
schema.method({
encryptPassword : function(password) {
return crypto.createHmac('sha512', this.PassSalt).update(password).digest('hex');
},
checkPassword : function(password) {
if ((this.PassHash)&&(password))
return this.encryptPassword(password+'') === this.PassHash;
else return false;
}
});
return schema;
}
}
}Last updated