Commit 1b439aca by zCaesar

blockout random mqttjs

parent 1d36c327
......@@ -25,7 +25,6 @@ function authCheck(client_id, token, password, callback) {
if (require('jwt-verify').verify(token).res) { // auth realtimedb by token
callback(true);
}
else {
console.log('token :' + token)
seneca.act('ms:tokenregistry, cmd:getAttributes, type:device, tokencode:' + token, function (err, res) {
......@@ -98,30 +97,46 @@ module.exports = function (options = {}) {
console.log('auth_on_register-------------');
console.log(req.body);
}
var client_id = req.body.client_id
var cachekey = 'auth:' + req.body.client_id + ':' + req.body.username + ':' + req.body.password;
var authstatus = cache.get(cachekey);
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
cache.set(cachekey, result);
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
console.log(client_id)
console.log(client_id.indexOf('-'))
if (client_id.indexOf('mqttjs_') !== -1) {
res.send({
"result": status ? "ok" : "no"
});
})
"result": result ? "ok" : "no"
});
}
else {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
res.send({
"result": status ? "ok" : "no"
});
})
}
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
});
}
else {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
if (client_id.indexOf('mqttjs_') !== -1) {
res.send({
"result": status ? "ok" : "no"
});
})
"result": authstatus ? "ok" : "no"
});
}
else {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
res.send({
"result": status ? "ok" : "no"
});
})
}
}
next();
}
......
......@@ -7,8 +7,10 @@ module.exports = function(options = {}) {
}
function doRedis(client_id) {
require('./redis/on_offline').on_offline_redis(client_id).then(status => {
console.log('redis:status: ' + status)
})
if (client_id.indexOf('mqttjs_') !== -1) {
require('./redis/on_offline').on_offline_redis(client_id).then(status => {
console.log('redis:status: ' + status)
})
}
}
}
\ 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