Commit fe0fbce2 by zCaesar

add client_id

parent 36200e3c
...@@ -33,6 +33,32 @@ module.exports = function (options = {}) { ...@@ -33,6 +33,32 @@ module.exports = function (options = {}) {
checkRealDB(req.body.username, (err, decoded) => { checkRealDB(req.body.username, (err, decoded) => {
if (err) { if (err) {
// Set Response // Set Response
var isShadow = require('./utils/getTopic').isShadow
if (isShadow(topic)) {
var _ftopic = require('./utils/getTopic').getTopic(topic, req.body.client_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 {
var getGroupID = require('./utils/getGroupID').getGroupID var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id) // console.log(_id)
...@@ -60,6 +86,7 @@ module.exports = function (options = {}) { ...@@ -60,6 +86,7 @@ module.exports = function (options = {}) {
next(); next();
}) })
} }
}
else { else {
console.log(decoded) console.log(decoded)
if (decoded.role === 'realtimedb') { if (decoded.role === 'realtimedb') {
......
...@@ -38,6 +38,32 @@ module.exports = function (options = {}) { ...@@ -38,6 +38,32 @@ module.exports = function (options = {}) {
checkRealDB(req.body.username, (err, decoded) => { checkRealDB(req.body.username, (err, decoded) => {
if (err) { if (err) {
// Set Response // Set Response
var isShadow = require('./utils/getTopic').isShadow
if (isShadow(topic)) {
var _ftopic = require('./utils/getTopic').getTopic(topic, req.body.client_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 {
var getGroupID = require('./utils/getGroupID').getGroupID var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id) // console.log(_id)
...@@ -65,6 +91,7 @@ module.exports = function (options = {}) { ...@@ -65,6 +91,7 @@ module.exports = function (options = {}) {
next(); next();
}) })
} }
}
else { else {
console.log(decoded) console.log(decoded)
if (decoded.role === 'realtimedb') { if (decoded.role === 'realtimedb') {
......
...@@ -17,3 +17,11 @@ function classifiedTopic(topic) { ...@@ -17,3 +17,11 @@ function classifiedTopic(topic) {
return '@client' return '@client'
} }
} }
function isShadow(topic) {
if (topic.indexOf('@shadow') !== -1) {
return true
}
else return false
}
module.exports.isShadow = isShadow
\ No newline at end of file
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