Commit 1c99fce2 by Chavee Issariyapat

fix bug

parent 47162778
......@@ -53,6 +53,11 @@ module.exports = function (options = {}) {
'retain': false
}
}
if (options.debug) {
console.log(response);
}
if (output.verb == 'get' || output.verb == 'read') {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
}
......
......@@ -6,17 +6,8 @@ var LRU = require("lru-cache"),
max: 500,
maxAge: 1000 * 60 * 5
});
var debug = false;
// for testing
// function authCheck(client_id, token, topic, callback) {
// callback(true);
// }
module.exports = function (options = {}) {
debug = options.debug || false;
return function (req, res, next) {
if (options.debug) {
......@@ -46,6 +37,7 @@ module.exports = function (options = {}) {
var GGID = require('./utils/getGroupID');
GGID.getGroupID(req.body.username, req.body.client_id, function(group) {
console.log(group);
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response
'topic': _ftopic,
......@@ -55,6 +47,11 @@ module.exports = function (options = {}) {
'result': 'ok',
'topics': _topic
}
if (options.debug) {
console.log(response);
}
res.send(response);
next();
});
......
......@@ -5,15 +5,17 @@ var auth_on_register_debug = process.env["AUTH_ON_REGISTER_DEBUG"] || false;
var auth_on_publish_debug = process.env["AUTH_ON_PUBLISH_DEBUG"] || true;
var auth_on_subscribe_debug = process.env["AUTH_ON_SUBSCRIBE_DEBUG"] || true;
var on_publish_debug = process.env["ON_PUBLISH_DEBUG"] || true;
var on_deliver_debug = process.env["ON_DELIVER_DEBUG"] || true;
var on_unsubscribe_debug = process.env["ON_UNSUBSCRIBE_DEBUG"] || true;
var restify = require('restify');
var auth_on_register = require('./auth_on_register')({ debug: auth_on_register_debug });
var auth_on_publish = require('./auth_on_publish')({ debug: auth_on_publish_debug });
var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscribe_debug });
var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver').on_deliver
var on_deliver = require('./on_deliver')({ debug: on_deliver_debug });
var on_unsubscribe = require('./on_unsubscribe')({ debug: on_unsubscribe_debug });
var signRole = require('./checkClientRole').signRole
var on_unsubscribe = require('./on_unsubscribe').on_unsubscribe
const server = restify.createServer({
name: 'authhook',
......
var modify = require('./utils/modify');
function on_deliver(req, res, next) {
console.log('----on_deliver-----')
var topics = modify.removeTempWordInTopic(req.body.topic)
console.log(req.body)
// console.log(topics)
var response = {
'result': 'ok',
'modifiers': {
"topic": topics
module.exports = function(options = {}) {
return function (req, res, next) {
console.log('----on_deliver-----')
var topics = modify.removeTempWordInTopic(req.body.topic)
console.log(req.body)
// console.log(topics)
var response = {
'result': 'ok',
'modifiers': {
"topic": topics
}
}
console.log(response);
res.send(response)
}
console.log(response);
res.send(response)
}
module.exports.on_deliver = on_deliver
module.exports.on_deliver = on_deliver
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
}
module.exports.joinTopic = joinTopic
\ No newline at end of file
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
}
}
\ No newline at end of file
function on_unsubscribe(req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
var token = req.body.username
var client_id = req.body.client_id
var response
module.exports = function(options = {}) {
return function (req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
var token = req.body.username
var client_id = req.body.client_id
var response
var decoded = require('./checkClientRole').checkRealDB(token)
if (decoded) {
if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' }
}
else response = { 'result': 'no' }
res.send(response);
next()
}
else {
var GGID = require('./utils/getGroupID');
GGID.getGroupID(token, client_id, function(group) {
if (group) {
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'unsub', group, client_id)
response = {
"result": "ok",
"topics": [_ftopic]
}
var decoded = require('./checkClientRole').checkRealDB(token)
if (decoded) {
if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' }
}
else response = { 'result': 'no' }
res.send(response);
next()
});
}
else {
var GGID = require('./utils/getGroupID');
GGID.getGroupID(token, client_id, function(group) {
if (group) {
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'unsub', group, client_id)
response = {
"result": "ok",
"topics": [_ftopic]
}
}
else response = { 'result': 'no' }
if (options.debug) {
console.log('on_unsubscribe-------------');
console.log(response);
}
res.send(response);
next()
});
}
}
}
module.exports.on_unsubscribe = on_unsubscribe
\ No newline at end of file
}
\ No newline at end of file
......@@ -3,9 +3,11 @@ var modify = require('./modify');
function rewriteTopic(topic, op, groupid, clientid, output) {
var chunk = topic.split('/');
console.log(groupid);
switch (chunk[0]) {
case '@msg' :
return modify.insertWordIntoTopic(topic, '!'+clientid, 1);
return modify.insertWordIntoTopic(topic, '!'+groupid, 1);
case '@shadow' :
if (chunk[1] == 'write' || chunk[1] == 'read') {
......
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