mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
refactor: pass less data into user object
This commit is contained in:
parent
4b9740cf5c
commit
1c0fd26496
@ -78,7 +78,7 @@ self.list = async (req, res, next) => {
|
||||
|
||||
self.change = async (req, res, next) => {
|
||||
try {
|
||||
const user = await utils.authorize(req)
|
||||
const user = await utils.authorize(req, 'token')
|
||||
|
||||
const newToken = await self.generateUniqueToken()
|
||||
if (!newToken) {
|
||||
|
@ -188,9 +188,16 @@ self.stripIndents = string => {
|
||||
return result
|
||||
}
|
||||
|
||||
self.assertUser = async token => {
|
||||
self.assertUser = async (token, fields) => {
|
||||
const _fields = ['id', 'username', 'enabled', 'timestamp', 'permission', 'registration']
|
||||
if (typeof fields === 'string') fields = [fields]
|
||||
if (Array.isArray(fields)) {
|
||||
_fields.push(...fields)
|
||||
}
|
||||
|
||||
const user = await db.table('users')
|
||||
.where('token', token)
|
||||
.select(_fields)
|
||||
.first()
|
||||
if (user) {
|
||||
if (user.enabled === false || user.enabled === 0) {
|
||||
@ -202,12 +209,12 @@ self.assertUser = async token => {
|
||||
}
|
||||
}
|
||||
|
||||
self.authorize = async req => {
|
||||
self.authorize = async (req, fields) => {
|
||||
const token = req.headers.token
|
||||
if (token === undefined) {
|
||||
throw new ClientError('No token provided.', { statusCode: 403 })
|
||||
}
|
||||
return self.assertUser(token)
|
||||
return self.assertUser(token, fields)
|
||||
}
|
||||
|
||||
self.generateThumbs = async (name, extname, force) => {
|
||||
|
Loading…
Reference in New Issue
Block a user