mirror of
https://github.com/status-im/codimd.git
synced 2025-01-27 12:35:35 +00:00
add hooks for hash password
Signed-off-by: BinotaLIU <me@binota.org>
This commit is contained in:
parent
d99346f037
commit
027195e973
@ -57,6 +57,18 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.addHook('beforeCreate', async function (user) {
|
||||||
|
// only do hash when password is presented
|
||||||
|
if (user.password) {
|
||||||
|
user.password = await User.hashPassword(user.password)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
User.addHook('beforeUpdate', async function (user) {
|
||||||
|
if (user.changed('password')) {
|
||||||
|
user.password = await User.hashPassword(user.password)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
User.associate = function (models) {
|
User.associate = function (models) {
|
||||||
User.hasMany(models.Note, {
|
User.hasMany(models.Note, {
|
||||||
foreignKey: 'ownerId',
|
foreignKey: 'ownerId',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user