2020-05-04 01:16:54 +00:00
|
|
|
const { Model } = require('flitter-orm')
|
|
|
|
const bcrypt = require('bcrypt')
|
2020-08-13 06:56:33 +00:00
|
|
|
const uuid = require('uuid').v4
|
2020-05-04 01:16:54 +00:00
|
|
|
|
|
|
|
class AppPasswordModel extends Model {
|
|
|
|
static get schema() {
|
|
|
|
return {
|
|
|
|
hash: String,
|
|
|
|
created: { type: Date, default: () => new Date },
|
|
|
|
expires: Date,
|
|
|
|
active: { type: Boolean, default: true },
|
|
|
|
name: String,
|
|
|
|
uuid: { type: String, default: uuid },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async set_hash(password) {
|
|
|
|
this.hash = await bcrypt.hash(password, 10)
|
|
|
|
if ( !this.uuid ) this.uuid = uuid()
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
async verify(password) {
|
|
|
|
return bcrypt.compare(password, this.hash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = AppPasswordModel
|