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,24 +97,39 @@ 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);
console.log(client_id)
console.log(client_id.indexOf('-'))
if (client_id.indexOf('mqttjs_') !== -1) {
res.send({
"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 {
if (client_id.indexOf('mqttjs_') !== -1) {
res.send({
"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({
......@@ -123,6 +137,7 @@ module.exports = function (options = {}) {
});
})
}
}
next();
}
else {
......
......@@ -7,8 +7,10 @@ module.exports = function(options = {}) {
}
function doRedis(client_id) {
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