Commit 99c5a125 by zCaesar

add check status before save redis

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