Commit 3d0afcba by zCaesar

add role to flow

parent d24dd439
...@@ -26,32 +26,59 @@ module.exports = function (options = {}) { ...@@ -26,32 +26,59 @@ module.exports = function (options = {}) {
var cachekey = 'pub:' + req.body.client_id + ':' + req.body.username + ':' + topic; var cachekey = 'pub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey); var authstatus = cache.get(cachekey);
// Set Response console.log(req.body)
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
var response = {
'result': 'ok',
'modifiers': {
'topic': _ftopic,
'qos': 0,
'retain': false
}
}
console.log(response)
if (typeof (authstatus) == 'undefined') { // checkRole
// cache missed var checkRealDB = require('./checkClientRole').checkRealDB
authCheck(req.body.client_id, req.body.username, topic, function (result) { checkRealDB(req.body.username, (err, decoded) => {
cache.set(cachekey, result); if (err) {
res.send(response); // Set Response
}); var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
var response = {
'result': 'ok',
'modifiers': {
'topic': _ftopic,
'qos': 0,
'retain': false
}
}
console.log(response)
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 { else {
res.send(response); 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();
}
} }
next();
}) })
} }
else { else {
......
...@@ -31,33 +31,59 @@ module.exports = function (options = {}) { ...@@ -31,33 +31,59 @@ module.exports = function (options = {}) {
var cachekey = 'sub:' + req.body.client_id + ':' + req.body.username + ':' + topic; var cachekey = 'sub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey); var authstatus = cache.get(cachekey);
console.log(req.body)
// checkRole // checkRole
var role = require('./checkClientRole') var checkRealDB = require('./checkClientRole').checkRealDB
// Set Response checkRealDB(req.body.username, (err, decoded) => {
var getGroupID = require('./utils/getGroupID').getGroupID if (err) {
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID // Set Response
// console.log(_id) var getGroupID = require('./utils/getGroupID').getGroupID
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
var _topic = [{ // setTopic for response // console.log(_id)
'topic': _ftopic, var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
'qos': 0 var _topic = [{ // setTopic for response
}] 'topic': _ftopic,
var response = { 'qos': 0
'result': 'ok', }]
'topics': _topic var response = {
} 'result': 'ok',
'topics': _topic
if (typeof (authstatus) == 'undefined') { }
// cache missed console.log(response)
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result); if (typeof (authstatus) == 'undefined') {
res.send(response); // 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 { else {
res.send(response); 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();
}
} }
next();
}) })
} }
else { else {
......
...@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) { ...@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) {
server.post('/authreg', auth_on_register); server.post('/authreg', auth_on_register);
server.post('/authpub', auth_on_publish); server.post('/authpub', auth_on_publish);
server.post('/authsub', auth_on_subscribe); 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('/ondeliver', on_deliver)
server.post('/onpub', on_publish) server.post('/onpub', on_publish)
server.post('/signRole', signRole) server.post('/signRole', signRole)
......
function on_deliver(req, res, next) { function on_deliver(req, res, next) {
var topics = beDesireTopic(req.body.topic) var topics = beDesireTopic(req.body.topic)
console.log('----on_deliver-----')
console.log(req.body)
console.log(topics)
var response = { var response = {
'result': 'ok', 'result': 'ok',
'modifiers': { 'modifiers': {
......
...@@ -14,7 +14,7 @@ module.exports = function(options={}) { ...@@ -14,7 +14,7 @@ module.exports = function(options={}) {
console.log('on_publish-------------'); console.log('on_publish-------------');
console.log(req.body); console.log(req.body);
} }
console.log(req.body)
var topic = req.body.topic; var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+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