Commit c911192b by zCaesar

Merge branch 'alpha-v2' into 'master'

edit datenow

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