Commit a23d9730 by zCaesar

redis

parents babf826c 9c233f79
.DS_Store
node_modules/
config/*.json
*.rdb
......@@ -101,6 +101,7 @@ module.exports = function (options = {}) {
}
var cachekey = 'auth:' + req.body.client_id + ':' + req.body.username + ':' + req.body.password;
var authstatus = cache.get(cachekey);
<<<<<<< HEAD
// if (typeof (authstatus) == 'undefined') {
// // cache missed
// authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
......@@ -157,6 +158,51 @@ module.exports = function (options = {}) {
} else {
res.send({
result: { error: 'not allowed' }
=======
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) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
if (status) {
res.send({
result: 'ok'
});
} else {
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) {
require('./redis/on_register').on_register_redis(req.body.client_id).then(status => {
console.log('redis:status: ' + status)
if (status) {
res.send({
result: 'ok'
});
} else {
res.send({
result: {error: 'not allowed'}
});
}
})
} else {
res.send({
result: {error: 'not allowed'}
>>>>>>> 9c233f79215090b0fd648f8b8b8061447ed746dc
});
}
})
......@@ -164,7 +210,11 @@ module.exports = function (options = {}) {
}
else {
res.send({
<<<<<<< HEAD
result: { error: 'not allowed' }
=======
result: 'no'
>>>>>>> 9c233f79215090b0fd648f8b8b8061447ed746dc
});
next();
}
......
......@@ -11,7 +11,7 @@ module.exports = function(options = {}) {
if (decoded) {
if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' }
response = { result: 'ok' }
}
else response = { result: {error: 'not allowed'} }
res.send(response);
......
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