tokenController.js 982 B

123456789101112131415161718192021222324252627
  1. const config = require('../config.js')
  2. const db = require('knex')(config.database)
  3. let tokenController = {}
  4. tokenController.verify = function(req, res, next){
  5. let type = req.headers.type
  6. let token = req.headers.token
  7. if(type === undefined) return res.json({ success: false, description: 'No type provided.' })
  8. if(token === undefined) return res.json({ success: false, description: 'No token provided.' })
  9. if(type !== 'client' && type !== 'admin') return res.json({ success: false, description: 'Wrong type provided.' })
  10. if(type === 'client'){
  11. if(token !== config.clientToken) return res.json({ success: false, description: 'Token mismatch.' })
  12. return res.json({ success: true })
  13. }
  14. if(type === 'admin'){
  15. if(token !== config.adminToken) return res.json({ success: false, description: 'Token mismatch.' })
  16. return res.json({ success: true })
  17. }
  18. return res.json({ success: false, description: '(╯°□°)╯︵ ┻━┻' })
  19. }
  20. module.exports = tokenController