Commit a23d9730 by zCaesar

redis

parents babf826c 9c233f79
.DS_Store .DS_Store
node_modules/ node_modules/
config/*.json config/*.json
*.rdb
...@@ -101,6 +101,7 @@ module.exports = function (options = {}) { ...@@ -101,6 +101,7 @@ 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);
<<<<<<< HEAD
// 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) {
...@@ -157,6 +158,51 @@ module.exports = function (options = {}) { ...@@ -157,6 +158,51 @@ module.exports = function (options = {}) {
} else { } else {
res.send({ res.send({
result: { error: 'not allowed' } 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 = {}) { ...@@ -164,7 +210,11 @@ module.exports = function (options = {}) {
} }
else { else {
res.send({ res.send({
<<<<<<< HEAD
result: { error: 'not allowed' } result: { error: 'not allowed' }
=======
result: 'no'
>>>>>>> 9c233f79215090b0fd648f8b8b8061447ed746dc
}); });
next(); next();
} }
......
...@@ -11,7 +11,7 @@ module.exports = function(options = {}) { ...@@ -11,7 +11,7 @@ module.exports = function(options = {}) {
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') { if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' } response = { result: 'ok' }
} }
else response = { result: {error: 'not allowed'} } else response = { result: {error: 'not allowed'} }
res.send(response); 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