Genesis commit
This commit is contained in:
36
persistence/models/password.js
Normal file
36
persistence/models/password.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
module.exports = function (sequelize, DataTypes, options) {
|
||||
const model = sequelize.define("password", {
|
||||
id: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: function() {
|
||||
return options.generateUniqueId()
|
||||
},
|
||||
primaryKey: true,
|
||||
unique: true
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
// primaryKey: true,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
set(val) {
|
||||
var hashedPassword = options != null && val != null && val.length > 0 ?
|
||||
bcrypt.hashSync(val, bcrypt.genSaltSync(11)) :
|
||||
null
|
||||
;
|
||||
this.setDataValue('password', hashedPassword);
|
||||
}
|
||||
// should have an accessor method the redacts this failed...
|
||||
}
|
||||
}, {
|
||||
comment: "hashed password"
|
||||
});
|
||||
|
||||
model.associate = (db) => {
|
||||
model.User = model.belongsTo(db.User);
|
||||
}
|
||||
|
||||
return model;
|
||||
};
|
||||
Reference in New Issue
Block a user