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) {
module.exports = function(options = {}) {
return function (req, res, next) {
console.log('----on_deliver-----')
var topics = modify.removeTempWordInTopic(req.body.topic)
console.log(req.body)
......@@ -13,11 +14,11 @@ function on_deliver(req, res, next) {
}
console.log(response);
res.send(response)
}
module.exports.on_deliver = on_deliver
}
module.exports.on_deliver = on_deliver
function joinTopic(topics) {
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
}
}
\ No newline at end of file
module.exports.joinTopic = joinTopic
\ No newline at end of file
function on_unsubscribe(req, res, next) {
module.exports = function(options = {}) {
return function (req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
......@@ -27,9 +28,15 @@ function on_unsubscribe(req, res, next) {
}
}
else response = { 'result': 'no' }
if (options.debug) {
console.log('on_unsubscribe-------------');
console.log(response);
}
res.send(response);
next()
});
}
}
}
\ No newline at end of file
module.exports.on_unsubscribe = on_unsubscribe
\ 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