WIP changing from auth to just 1 token
This commit is contained in:
parent
5f0ff7f6aa
commit
3a58b5b4b9
|
@ -4,34 +4,26 @@ const db = require('knex')(config.database)
|
||||||
let tokenController = {}
|
let tokenController = {}
|
||||||
|
|
||||||
tokenController.verify = function(req, res, next){
|
tokenController.verify = function(req, res, next){
|
||||||
let type = req.body.type
|
|
||||||
|
if(req.body.token === undefined) return res.json({ success: false, description: 'No token provided' })
|
||||||
let token = req.body.token
|
let token = req.body.token
|
||||||
|
|
||||||
if(type === undefined) return res.json({ success: false, description: 'No type provided.' })
|
db.table('users').where('token', token).then((user) => {
|
||||||
if(token === undefined) return res.json({ success: false, description: 'No token provided.' })
|
if(user.length === 0) return res.json({ success: false, description: 'Token mismatch' })
|
||||||
if(type !== 'client' && type !== 'admin') return res.json({ success: false, description: 'Wrong type provided.' })
|
|
||||||
|
|
||||||
if(type === 'client'){
|
|
||||||
if(token !== config.clientToken) return res.json({ success: false, description: 'Token mismatch.' })
|
|
||||||
return res.json({ success: true })
|
return res.json({ success: true })
|
||||||
}
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
||||||
|
|
||||||
if(type === 'admin'){
|
|
||||||
if(token !== config.adminToken) return res.json({ success: false, description: 'Token mismatch.' })
|
|
||||||
return res.json({ success: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json({ success: false, description: '(╯°□°)╯︵ ┻━┻' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenController.list = function(req, res, next){
|
tokenController.list = function(req, res, next){
|
||||||
if(req.headers.auth !== config.adminToken)
|
|
||||||
return res.status(401).json({ success: false, description: 'not-authorized'})
|
|
||||||
|
|
||||||
return res.json({
|
if(req.headers.auth === undefined) return res.json({ success: false, description: 'No token provided' })
|
||||||
clientToken: config.clientToken,
|
let token = req.headers.auth
|
||||||
adminToken: config.adminToken
|
|
||||||
})
|
db.table('users').where('token', token).then((user) => {
|
||||||
|
if(user.length === 0) return res.json({ success: false, description: 'Token mismatch' })
|
||||||
|
return res.json({ success: true, token: token })
|
||||||
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenController.change = function(req, res, next){
|
tokenController.change = function(req, res, next){
|
||||||
|
|
Loading…
Reference in New Issue