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 },
|
2021-12-14 22:40:15 +00:00
|
|
|
accessed: Date,
|
2020-05-04 01:16:54 +00:00
|
|
|
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
|