Commit 3d0afcba by zCaesar

add role to flow

parent d24dd439
......@@ -26,6 +26,12 @@ module.exports = function (options = {}) {
var cachekey = 'pub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey);
console.log(req.body)
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
......@@ -55,6 +61,27 @@ module.exports = function (options = {}) {
})
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
}
else {
res.send(response);
}
next();
}
}
})
}
else {
res.send({
"result": "no"
});
......
......@@ -31,8 +31,12 @@ module.exports = function (options = {}) {
var cachekey = 'sub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey);
console.log(req.body)
// checkRole
var role = require('./checkClientRole')
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
......@@ -46,6 +50,7 @@ module.exports = function (options = {}) {
'result': 'ok',
'topics': _topic
}
console.log(response)
if (typeof (authstatus) == 'undefined') {
// cache missed
......@@ -61,6 +66,27 @@ module.exports = function (options = {}) {
})
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
}
else {
res.send(response);
}
next();
}
}
})
}
else {
res.send({
"result": "no"
});
......
......@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) {
server.post('/authreg', auth_on_register);
server.post('/authpub', auth_on_publish);
server.post('/authsub', auth_on_subscribe);
server.post('/onsub', (req,res,next) => {
console.log(req.body)
res.send('')
})
server.post('/ondeliver', on_deliver)
server.post('/onpub', on_publish)
server.post('/signRole', signRole)
......
function on_deliver(req, res, next) {
var topics = beDesireTopic(req.body.topic)
console.log('----on_deliver-----')
console.log(req.body)
console.log(topics)
var response = {
'result': 'ok',
'modifiers': {
......
......@@ -14,7 +14,7 @@ module.exports = function(options={}) {
console.log('on_publish-------------');
console.log(req.body);
}
console.log(req.body)
var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment