2019-03-05 23:55:31 +00:00
|
|
|
const { generateToken } = require('../util')
|
2019-02-03 19:16:02 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
attributes: {
|
|
|
|
id: {
|
|
|
|
type: 'number',
|
|
|
|
unique: true,
|
|
|
|
autoIncrement: true
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
model: 'User',
|
|
|
|
required: true
|
|
|
|
},
|
2019-02-26 03:29:18 +00:00
|
|
|
name: {
|
2019-02-03 19:16:02 +00:00
|
|
|
type: 'string',
|
|
|
|
required: true
|
|
|
|
},
|
2019-02-26 03:29:18 +00:00
|
|
|
url: 'string',
|
2019-02-24 21:27:24 +00:00
|
|
|
whitelisted: 'boolean',
|
2019-02-26 03:29:18 +00:00
|
|
|
verified: 'boolean',
|
|
|
|
verification_key: 'string',
|
2019-02-24 21:27:24 +00:00
|
|
|
appid: {
|
|
|
|
type: 'string'
|
2019-02-03 19:16:02 +00:00
|
|
|
},
|
|
|
|
secret: {
|
2019-02-24 21:27:24 +00:00
|
|
|
type: 'string'
|
2019-02-03 19:16:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeCreate: async function (key, next) {
|
2019-02-24 21:27:24 +00:00
|
|
|
key.appid = await generateToken({ bytes: 12 })
|
2019-02-03 19:16:02 +00:00
|
|
|
key.secret = await generateToken({ bytes: 48 })
|
2019-02-26 22:17:30 +00:00
|
|
|
key.verification_key = await generateToken({ bytes: 24, base: 'hex' })
|
2019-02-03 19:16:02 +00:00
|
|
|
next()
|
|
|
|
},
|
|
|
|
beforeUpdate: async function (key, next) {
|
|
|
|
key.secret = await generateToken({ bytes: 48 })
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}
|