Commit 1b439aca by zCaesar

blockout random mqttjs

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