salix/services/loopback/common/models/account.js

17 lines
424 B
JavaScript
Raw Normal View History

2018-02-15 13:35:04 +00:00
const md5 = require('md5');
2017-10-13 14:22:45 +00:00
module.exports = function(Self) {
// Validations
Self.validatesUniquenessOf('name', {
message: 'Ya existe un usuario con ese nombre'
});
2018-02-15 13:35:04 +00:00
Self.observe('before save', (ctx, next) => {
if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password) {
ctx.data.password = md5(ctx.data.password);
}
next();
});
2017-10-13 14:22:45 +00:00
};