mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Print and save tokens
This commit is contained in:
parent
7b72c3e560
commit
570f6c3ce3
@ -5,8 +5,8 @@ let galleryController = {}
|
||||
|
||||
galleryController.list = function(req, res, next){
|
||||
|
||||
if(config.TOKEN !== '')
|
||||
if(req.headers.auth !== config.TOKEN)
|
||||
if(config.TOKEN === true)
|
||||
if(req.headers.auth === config.clientToken)
|
||||
return res.status(401).send('not-authorized')
|
||||
|
||||
db.table('gallery').select('id', 'name').then((data) => {
|
||||
@ -16,8 +16,8 @@ galleryController.list = function(req, res, next){
|
||||
|
||||
galleryController.test = function(req, res, next){
|
||||
|
||||
if(config.TOKEN !== '')
|
||||
if(req.headers.auth !== config.TOKEN)
|
||||
if(config.TOKEN === true)
|
||||
if(req.headers.auth === config.clientToken)
|
||||
return res.status(401).send('not-authorized')
|
||||
|
||||
let testdata = [
|
||||
|
@ -22,8 +22,8 @@ const upload = multer({
|
||||
|
||||
uploadsController.upload = function(req, res, next){
|
||||
|
||||
if(config.TOKEN !== '')
|
||||
if(req.headers.auth !== config.TOKEN)
|
||||
if(config.TOKEN === true)
|
||||
if(req.headers.auth !== config.clientToken)
|
||||
return res.status(401).send('not-authorized')
|
||||
|
||||
let gallery = req.headers.gallery
|
||||
@ -63,8 +63,8 @@ uploadsController.upload = function(req, res, next){
|
||||
|
||||
uploadsController.list = function(req, res){
|
||||
|
||||
if(config.TOKEN !== '')
|
||||
if(req.headers.auth !== config.TOKEN)
|
||||
if(config.TOKEN === true)
|
||||
if(req.headers.auth !== config.clientToken)
|
||||
return res.status(401).send('not-authorized')
|
||||
|
||||
db.table('files').then((files) => {
|
||||
|
@ -27,35 +27,38 @@ let init = function(db, config){
|
||||
|
||||
// == Generate a 1 time token == //
|
||||
db.table('tokens').then((tokens) => {
|
||||
if(tokens.length === 0){
|
||||
|
||||
// This is the first launch of the app
|
||||
let clientToken = require('randomstring').generate()
|
||||
let adminToken = require('randomstring').generate()
|
||||
if(tokens.length !== 0) return printAndSave(config, tokens[0].value, tokens[1].value)
|
||||
|
||||
db.table('tokens').insert(
|
||||
[
|
||||
{
|
||||
name: 'client',
|
||||
value: clientToken
|
||||
},
|
||||
{
|
||||
name: 'admin',
|
||||
value: adminToken
|
||||
}
|
||||
]
|
||||
).then(() => {
|
||||
console.log('Your client token is: ' + clientToken)
|
||||
console.log('Your admin token is: ' + adminToken)
|
||||
config.clientToken = clientToken
|
||||
config.adminToken = adminToken
|
||||
})
|
||||
// This is the first launch of the app
|
||||
let clientToken = require('randomstring').generate()
|
||||
let adminToken = require('randomstring').generate()
|
||||
|
||||
db.table('tokens').insert(
|
||||
[
|
||||
{
|
||||
name: 'client',
|
||||
value: clientToken
|
||||
},
|
||||
{
|
||||
name: 'admin',
|
||||
value: adminToken
|
||||
}
|
||||
]
|
||||
).then(() => {
|
||||
printAndSave(config, clientToken, adminToken)
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function printAndSave(config, clientToken, adminToken){
|
||||
console.log('Your client token is: ' + clientToken)
|
||||
console.log('Your admin token is: ' + adminToken)
|
||||
config.clientToken = clientToken
|
||||
config.adminToken = adminToken
|
||||
}
|
||||
|
||||
module.exports = init
|
@ -4,15 +4,15 @@ const uploadController = require('../controllers/uploadController')
|
||||
const galleryController = require('../controllers/galleryController')
|
||||
|
||||
routes.get ('/check', (req, res, next) => {
|
||||
if(config.TOKEN === '')
|
||||
if(config.TOKEN === true)
|
||||
return res.json({token: false})
|
||||
return res.json({token: true})
|
||||
})
|
||||
|
||||
routes.get('/info', (req, res, next) => {
|
||||
|
||||
if(config.TOKEN !== '')
|
||||
if(req.headers.auth !== config.TOKEN)
|
||||
if(config.TOKEN === true)
|
||||
if(req.headers.auth !== config.clientToken)
|
||||
return res.status(401).send('not-authorized')
|
||||
|
||||
return res.json({
|
||||
|
Loading…
Reference in New Issue
Block a user