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
1b439aca
Commit
1b439aca
authored
Nov 15, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blockout random mqttjs
parent
1d36c327
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
15 deletions
+33
-15
authhook/auth_on_register.js
+27
-12
authhook/on_offline.js
+6
-3
No files found.
authhook/auth_on_register.js
View file @
1b439aca
...
...
@@ -25,7 +25,6 @@ function authCheck(client_id, token, password, callback) {
if
(
require
(
'jwt-verify'
).
verify
(
token
).
res
)
{
// auth realtimedb by token
callback
(
true
);
}
else
{
console
.
log
(
'token :'
+
token
)
seneca
.
act
(
'ms:tokenregistry, cmd:getAttributes, type:device, tokencode:'
+
token
,
function
(
err
,
res
)
{
...
...
@@ -98,30 +97,46 @@ module.exports = function (options = {}) {
console
.
log
(
'auth_on_register-------------'
);
console
.
log
(
req
.
body
);
}
var
client_id
=
req
.
body
.
client_id
var
cachekey
=
'auth:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
req
.
body
.
password
;
var
authstatus
=
cache
.
get
(
cachekey
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
req
.
body
.
password
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
console
.
log
(
client_id
)
console
.
log
(
client_id
.
indexOf
(
'-'
))
if
(
client_id
.
indexOf
(
'mqttjs_'
)
!==
-
1
)
{
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
});
})
"result"
:
result
?
"ok"
:
"no"
});
}
else
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
});
})
}
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
});
}
else
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
if
(
client_id
.
indexOf
(
'mqttjs_'
)
!==
-
1
)
{
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
});
})
"result"
:
authstatus
?
"ok"
:
"no"
});
}
else
{
require
(
'./redis/on_register'
).
on_register_redis
(
req
.
body
.
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
res
.
send
({
"result"
:
status
?
"ok"
:
"no"
});
})
}
}
next
();
}
...
...
authhook/on_offline.js
View file @
1b439aca
...
...
@@ -7,8 +7,10 @@ module.exports = function(options = {}) {
}
function
doRedis
(
client_id
)
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
})
if
(
client_id
.
indexOf
(
'mqttjs_'
)
!==
-
1
)
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
})
}
}
}
\ No newline at end of file
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