Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
877a1dc1
Commit
877a1dc1
authored
Nov 06, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://dev.nexpie.com/stack/vernemq
parents
412aa10d
c911192b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
authhook/auth_on_register.js
+3
-2
authhook/validator.js
+4
-2
No files found.
authhook/auth_on_register.js
View file @
877a1dc1
...
...
@@ -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
);
...
...
authhook/validator.js
View file @
877a1dc1
...
...
@@ -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
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment