Commit b0008ed3 by zCaesar

fix

parent e46d316b
...@@ -30,6 +30,7 @@ function authCheck(client_id, token, password, callback) { ...@@ -30,6 +30,7 @@ function authCheck(client_id, token, password, callback) {
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) {
console.log('result : ' + util.inspect(res.result, false, null, true)) console.log('result : ' + util.inspect(res.result, false, null, true))
if (res.result) { if (res.result) {
console.log(res.result)
var token_profile = (res && res.result && res.result[0]) ? res.result[0] : {}; var token_profile = (res && res.result && res.result[0]) ? res.result[0] : {};
var mqttauth = { var mqttauth = {
clientid: client_id, clientid: client_id,
...@@ -103,7 +104,7 @@ module.exports = function (options = {}) { ...@@ -103,7 +104,7 @@ module.exports = function (options = {}) {
// 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);
if (!result) { if (result) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => { require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status) console.log('redis:status: ' + status)
res.send({ res.send({
......
...@@ -3,7 +3,7 @@ var redis = new Redis() ...@@ -3,7 +3,7 @@ var redis = new Redis()
function on_message_redis(deviceid, payload) { // first time to access on authhook auth_on_register function on_message_redis(deviceid, payload) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (deviceid.indexOf('mqtt') === 0 && deviceid.length !== 36) { if (deviceid.indexOf('mqtt') === 0 || deviceid.length !== 36) {
console.log(deviceid) console.log(deviceid)
resolve(true) resolve(true)
} }
......
...@@ -3,7 +3,7 @@ var redis = new Redis() ...@@ -3,7 +3,7 @@ var redis = new Redis()
function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register function on_offline_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (deviceid.indexOf('mqtt') === 0 && deviceid.length !== 36) { if (deviceid.indexOf('mqtt') === 0 || deviceid.length !== 36) {
resolve(true) resolve(true)
} }
else { else {
......
...@@ -3,7 +3,7 @@ var redis = new Redis() ...@@ -3,7 +3,7 @@ var redis = new Redis()
function on_register_redis(deviceid) { // first time to access on authhook auth_on_register function on_register_redis(deviceid) { // first time to access on authhook auth_on_register
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (deviceid.indexOf('mqtt') === 0 && deviceid.length !== 36) { if (deviceid.indexOf('mqtt') === 0 || deviceid.length !== 36) {
resolve(true) resolve(true)
} }
else { else {
......
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