Commit fc8c1224 by Chavee Issariyapat

add kb authen log

parent 855690d9
......@@ -6,9 +6,14 @@ var LRU = require("lru-cache") ,
maxAge: 1000 * 60 * 5
});
var authclient = require('seneca')({log: 'silent'})
const Seneca = require('seneca');
let authclient = Seneca({log: 'silent'})
.client({port: config.get('authserv_port'), host: config.get('authserv_host')});
let logclient = Seneca({log: 'silent'})
.client({ port: config.get('kblog_port'), host: config.get('kblog_host') });
// for testing
function authCheck(client_id, token, password, callback) {
......@@ -22,6 +27,18 @@ function authCheck(client_id, token, password, callback) {
});
}
function sendAuthLog(deviceid) {
let payload = {
clientid: deviceid, //kidbright mac address or UUID of mobile
status: 'online', //connection status 'online' or 'offline'
}
//console.log(payload)
logclient.act({ role:'log',cmd:'connect', message: JSON.stringify(payload) }, function (err, res) {
//console.log(err+' | '+res.result);
})
}
module.exports = function(options={}) {
return function(req, res, next) {
......@@ -38,12 +55,18 @@ module.exports = function(options={}) {
// cache missed
authCheck(req.body.client_id, req.body.username, req.body.password, function(result) {
cache.set(cachekey, result);
if (result) {
sendAuthLog(req.body.client_id);
}
res.send({
"result": result?"ok":"no"
});
});
}
else {
if (authstatus) {
sendAuthLog(req.body.client_id);
}
res.send({
"result": authstatus?"ok":"no"
});
......
{
"authserv_host" : "AUTH_SERVICE_HOST",
"authserv_port" : "AUTH_SERVICE_PORT"
"authserv_port" : "AUTH_SERVICE_PORT",
"kblog_host" : "KBLOG_HOST",
"kblog_port" : "KBLOG_PORT"
}
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