mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Updated RESTApi to have tokens also
This commit is contained in:
@@ -5,6 +5,8 @@ var mongo_db_cred = require(path.join(__dirname, '../../config/mongo_config.js')
|
||||
var mongojs = require('mongojs');
|
||||
var db = mongojs(mongo_db_cred.config);
|
||||
var token_db = mongojs("tokens");
|
||||
var uniqid = require('uniqid');
|
||||
var crypto = require('crypto');
|
||||
|
||||
router.use(function(req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
@@ -164,6 +166,17 @@ router.route('/api/token').get(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/api_token').get(function(req, res){
|
||||
if(req.isAuthenticated()){
|
||||
var id = crypto.createHash('sha256').update(uniqid()).digest('base64');
|
||||
token_db.collection("api_token").insert({token: id}, function(err, docs){
|
||||
res.json({token: id});
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/delete').post(function(req, res){
|
||||
if(req.isAuthenticated()){
|
||||
var list = req.body._id;
|
||||
|
||||
Reference in New Issue
Block a user