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
08bc1e1c
Commit
08bc1e1c
authored
Sep 16, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
can sub group
parent
f1ffcccf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
13 deletions
+26
-13
authhook/auth_on_subscribe.js
+26
-13
No files found.
authhook/auth_on_subscribe.js
View file @
08bc1e1c
var
config
=
require
(
'config'
);
var
config
=
require
(
'config'
);
// https://github.com/isaacs/node-lru-cache
// https://github.com/isaacs/node-lru-cache
var
LRU
=
require
(
"lru-cache"
)
,
var
LRU
=
require
(
"lru-cache"
),
cache
=
LRU
({
cache
=
LRU
({
max
:
500
,
max
:
500
,
maxAge
:
1000
*
60
*
5
maxAge
:
1000
*
60
*
5
...
@@ -12,13 +13,13 @@ function authCheck(client_id, token, topic, callback) {
...
@@ -12,13 +13,13 @@ function authCheck(client_id, token, topic, callback) {
callback
(
true
);
callback
(
true
);
}
}
module
.
exports
=
function
(
options
=
{})
{
module
.
exports
=
function
(
options
=
{})
{
debug
=
options
.
debug
||
false
;
debug
=
options
.
debug
||
false
;
return
function
(
req
,
res
,
next
)
{
return
function
(
req
,
res
,
next
)
{
if
(
debug
)
{
if
(
options
.
debug
)
{
console
.
log
(
'auth_on_subscribe-------------'
);
console
.
log
(
'auth_on_subscribe-------------'
);
console
.
log
(
req
.
body
);
console
.
log
(
req
.
body
);
}
}
...
@@ -27,24 +28,35 @@ module.exports = function(options={}) {
...
@@ -27,24 +28,35 @@ module.exports = function(options={}) {
var
authstatus
;
var
authstatus
;
var
topic
=
req
.
body
.
topics
[
0
].
topic
;
var
topic
=
req
.
body
.
topics
[
0
].
topic
;
var
cachekey
=
'sub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
cachekey
=
'sub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// Set Response
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
// console.log(_id)
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
'qos'
:
0
}]
var
response
=
{
'result'
:
'ok'
,
'topics'
:
_topic
}
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
cache
.
set
(
cachekey
,
result
);
res
.
send
({
res
.
send
(
response
);
"result"
:
result
?
"ok"
:
"no"
});
});
});
}
}
else
{
else
{
res
.
send
({
res
.
send
(
response
);
"result"
:
authstatus
?
"ok"
:
"no"
});
}
}
next
();
next
();
})
}
}
else
{
else
{
res
.
send
({
res
.
send
({
...
@@ -54,3 +66,4 @@ module.exports = function(options={}) {
...
@@ -54,3 +66,4 @@ module.exports = function(options={}) {
}
}
}
}
}
}
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