Commit 99c5a125 by zCaesar

add check status before save redis

parent 742e2089
......@@ -62,11 +62,10 @@ module.exports = function (options = {}) {
}
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);
// if (result) {
if (typeof (authstatus) == 'undefined') {
authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
cache.set(cachekey, result);
if (result) {
try {
on_register_redis(req.body.client_id)
res.send({ result: 'ok' });
......@@ -74,21 +73,19 @@ module.exports = function (options = {}) {
catch (e) {
res.send({ result: { error: 'not allowed' } });
}
// } else {
// res.send({ result: { error: 'not allowed' } });
// }
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
// });
// }
// else {
// if (authstatus) {
// on_register_redis(req.body.client_id)
// res.send({ result: 'ok' });
// } else {
// res.send({ result: { error: 'not allowed' } });
// }
// }
} else {
res.send({ result: { error: 'not allowed' } });
}
});
}
else {
if (authstatus) {
on_register_redis(req.body.client_id)
res.send({ result: 'ok' });
} else {
res.send({ result: { error: 'not allowed' } });
}
}
next();
}
else {
......
......@@ -6,8 +6,11 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
else {
var information = setValue(deviceid)
redis.hset(information.keys, 'status', information.status, 'offline_on', information.offline_on)
deviceUsageCount()
var status = redis.hget(information.keys, 'status')
if (status !== false) {
redis.hset(information.keys, 'status', information.status, 'offline_on', information.offline_on)
deviceUsageCount()
}
}
}
module.exports.on_offline_redis = on_offline_redis
......
......@@ -7,9 +7,11 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
else {
var information = setValue(deviceid)
redis.hdel(information.keys, 'offline_on')
console.log(information.keys)
redis.hset(information.keys, 'status', information.status, 'register_on', information.register_on, 'last_check', information.last_check)
deviceUsageCount()
var status = redis.hget(information.keys, 'status')
if (status !== true) {
redis.hset(information.keys, 'status', information.status, 'register_on', information.register_on, 'last_check', information.last_check)
deviceUsageCount()
}
}
}
module.exports.on_register_redis = on_register_redis
......
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