Commit 877a1dc1 by Chavee Issariyapat

Merge branch 'master' of https://dev.nexpie.com/stack/vernemq

parents 412aa10d c911192b
......@@ -29,7 +29,7 @@ function authCheck(client_id, token, password, callback) {
else {
console.log('token :' + token)
seneca.act('ms:tokenregistry, cmd:getAttributes, type:device, tokencode:' + token, function (err, res) {
// console.log('result : ' + util.inspect(res.result, false, null, true))
console.log('result : ' + util.inspect(res.result, false, null, true))
if (res.result) {
var token_profile = (res && res.result && res.result[0]) ? res.result[0] : {};
var mqttauth = {
......@@ -37,7 +37,8 @@ function authCheck(client_id, token, password, callback) {
token: token,
password: password
};
callback(validator.auth_connect(mqttauth, token_profile));
console.log(util.inspect(validator.auth_connect(mqttauth, token_profile), false, null, true))
callback(validator.auth_connect(mqttauth, token_profile).status);
}
else {
callback(false);
......
......@@ -25,6 +25,8 @@ module.exports.auth_connect = auth_connect
}
*/
function auth_connect(mqttauth, token_profile) {
var dateNow = Math.floor(Date.now() / 1000)
var res = {
status : true
}
......@@ -40,8 +42,8 @@ function auth_connect(mqttauth, token_profile) {
}
if (!found) return {status: false, reason: 'uneligible'};
}
if (Date.now() > token_profile.exp) return {status: false, reason: 'expired'};
if (token_profile.nbf && (Date.now() < token_profile.nbf)) return {status: false, reason: 'uneligible'};
if (dateNow > token_profile.exp) return {status: false, reason: 'expired'};
if (token_profile.nbf && (dateNow < token_profile.nbf)) return {status: false, reason: 'uneligible'};
return {status: true};
}
......
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