CoreID/app/models/auth/PasswordReset.model.js

25 lines
622 B
JavaScript
Raw Normal View History

2020-05-04 01:16:54 +00:00
const { Model } = require('flitter-orm')
const bcrypt = require('bcrypt')
class PasswordResetModel extends Model {
static get schema() {
return {
reset_on: { type: Date, default: () => new Date },
old_hash: String,
hash: String,
reason: { type: String, default: 'user' }, // 'user' | 'lockout'
}
}
async set_hash(password) {
this.hash = await bcrypt.hash(password, 10)
return this
}
async check(password) {
return await bcrypt.compare(password, this.hash)
}
}
module.exports = exports = PasswordResetModel