Commit 203665ed by Mine ArithmeticOp

check group not null before pubsub

parent f9fd9373
...@@ -27,7 +27,7 @@ module.exports = function (options = {}) { ...@@ -27,7 +27,7 @@ module.exports = function (options = {}) {
var response var response
var decoded = require('jwt-verify').verify(req.body.username).res var decoded = require('jwt-verify').verify(req.body.username).res
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' } if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' } else response = { 'result': 'no' }
...@@ -39,27 +39,31 @@ module.exports = function (options = {}) { ...@@ -39,27 +39,31 @@ module.exports = function (options = {}) {
var output = {}; var output = {};
GGID.getGroupID(req.body.username, req.body.client_id, function (group) { GGID.getGroupID(req.body.username, req.body.client_id, function (group) {
console.log('group: ' + group) if (group) {
var _ftopic = require('./utils/router').rewriteTopic(topic, 'pub', group, req.body.client_id, output); // get topic where concat with groupID var _ftopic = require('./utils/router').rewriteTopic(topic, 'pub', group, req.body.client_id, output); // get topic where concat with groupID
response = { response = {
'result': 'ok', 'result': 'ok',
'modifiers': { 'modifiers': {
'topic': _ftopic, 'topic': _ftopic,
'qos': 0, 'qos': 0,
'retain': false 'retain': false
}
} }
}
if (options.debug) { if (options.debug) {
console.log(response); console.log(response);
} }
if (output.verb == 'get' || output.verb == 'read') { if (output.verb == 'get' || output.verb == 'read') {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64'); response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
}
res.send(response);
next();
}
else {
res.send({ "result": "no" });
next();
} }
res.send(response);
next();
}); });
} }
} }
......
...@@ -32,13 +32,13 @@ function authCheck(client_id, token, password, callback) { ...@@ -32,13 +32,13 @@ function authCheck(client_id, token, password, callback) {
// console.log('result : ' + util.inspect(res.result, false, null, true)) // console.log('result : ' + util.inspect(res.result, false, null, true))
if (res.result) { if (res.result) {
var token_profile = (res && res.result && res.result[0]) ? res.result[0] : {}; var token_profile = (res && res.result && res.result[0]) ? res.result[0] : {};
console.log('token_profile: ' + token_profile) console.log('token_profile: ' + util.inspect(token_profile, false, null, true))
var mqttauth = { var mqttauth = {
clientid: client_id, clientid: client_id,
token: token, token: token,
password: password password: password
}; };
console.log('mqttauth: ' + mqttauth) console.log('mqttauth: ' + util.inspect(mqttauth, false, null, true))
callback(validator.auth_connect(mqttauth, token_profile)); callback(validator.auth_connect(mqttauth, token_profile));
} }
else { else {
......
...@@ -26,7 +26,7 @@ module.exports = function (options = {}) { ...@@ -26,7 +26,7 @@ module.exports = function (options = {}) {
} }
var response var response
var decoded = require('jwt-verify').verify(req.body.username).res var decoded = require('jwt-verify').verify(req.body.username).res
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' } if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' } else response = { 'result': 'no' }
...@@ -37,23 +37,28 @@ module.exports = function (options = {}) { ...@@ -37,23 +37,28 @@ module.exports = function (options = {}) {
var GGID = require('./utils/getGroupID'); var GGID = require('./utils/getGroupID');
GGID.getGroupID(req.body.username, req.body.client_id, function (group) { GGID.getGroupID(req.body.username, req.body.client_id, function (group) {
console.log('group: ' + group) if (group) {
var _ftopic = require('./utils/router').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID var _ftopic = require('./utils/router').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response var _topic = [{ // setTopic for response
'topic': _ftopic, 'topic': _ftopic,
'qos': 0 'qos': 0
}] }]
response = { response = {
'result': 'ok', 'result': 'ok',
'topics': _topic 'topics': _topic
} }
if (options.debug) { if (options.debug) {
console.log(response); console.log(response);
} }
res.send(response); res.send(response);
next(); next();
}
else {
res.send({ "result": "no" });
next();
}
}); });
} }
} }
......
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