Commit 3d0afcba by zCaesar

add role to flow

parent d24dd439
......@@ -26,32 +26,59 @@ module.exports = function (options = {}) {
var cachekey = 'pub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey);
// 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)
console.log(req.body)
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
// 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
// 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 {
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 {
......
......@@ -31,33 +31,59 @@ 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')
// 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 _topic = [{ // setTopic for response
'topic': _ftopic,
'qos': 0
}]
var response = {
'result': 'ok',
'topics': _topic
}
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
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
// console.log(_id)
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
var _topic = [{ // setTopic for response
'topic': _ftopic,
'qos': 0
}]
var response = {
'result': 'ok',
'topics': _topic
}
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 {
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 {
......
......@@ -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