aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorPitu <[email protected]>2017-01-18 04:51:42 -0300
committerPitu <[email protected]>2017-01-18 04:51:42 -0300
commitde130602f93f05360a3838d93a0f9d1cbb470153 (patch)
treea77f54c0a5b4dc10a9a48690a06b804a2a9398ad /controllers
parentAdded browsing galleries from dashboard (diff)
downloadhost.fuwn.me-de130602f93f05360a3838d93a0f9d1cbb470153.tar.xz
host.fuwn.me-de130602f93f05360a3838d93a0f9d1cbb470153.zip
Added changing of tokens from the dashboard
Diffstat (limited to 'controllers')
-rw-r--r--controllers/tokenController.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/controllers/tokenController.js b/controllers/tokenController.js
index 54c2a1f..91cc292 100644
--- a/controllers/tokenController.js
+++ b/controllers/tokenController.js
@@ -24,4 +24,37 @@ tokenController.verify = function(req, res, next){
return res.json({ success: false, description: '(╯°□°)╯︵ ┻━┻' })
}
+tokenController.list = function(req, res, next){
+ if(req.headers.auth !== config.adminToken)
+ return res.status(401).send('not-authorized')
+
+ return res.json({
+ clientToken: config.clientToken,
+ adminToken: config.adminToken
+ })
+}
+
+tokenController.change = function(req, res, next){
+ if(req.headers.auth !== config.adminToken)
+ return res.status(401).send('not-authorized')
+
+ let type = req.headers.type
+ let token = req.headers.token
+
+ if(type === undefined) return res.json({ success: false, description: 'No type provided.' })
+ if(token === undefined) return res.json({ success: false, description: 'No token provided.' })
+ if(type !== 'client' && type !== 'admin') return res.json({ success: false, description: 'Wrong type provided.' })
+
+ db.table('tokens').where('name', type).update({ value: token, timestamp: Math.floor(Date.now() / 1000) })
+ .then(() => {
+
+ if(type === 'client')
+ config.clientToken = token
+ else if(type === 'admin')
+ config.adminToken = token
+
+ res.json({ success: true })
+ })
+}
+
module.exports = tokenController \ No newline at end of file