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
f78abcd2
Commit
f78abcd2
authored
Sep 17, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'alpha-test' of
https://dev.nexpie.com/stack/vernemq
into alpha-test
parents
410ac110
fe0fbce2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
12 deletions
+74
-12
authhook/auth_on_publish.js
+32
-5
authhook/auth_on_subscribe.js
+32
-5
authhook/utils/getTopic.js
+10
-2
No files found.
authhook/auth_on_publish.js
View file @
f78abcd2
...
...
@@ -33,10 +33,9 @@ module.exports = function (options = {}) {
checkRealDB
(
req
.
body
.
username
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
// 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
isShadow
=
require
(
'./utils/getTopic'
).
isShadow
if
(
isShadow
(
topic
))
{
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
...
...
@@ -58,7 +57,35 @@ module.exports = function (options = {}) {
res
.
send
(
response
);
}
next
();
})
}
else
{
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
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
}
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
})
}
}
else
{
console
.
log
(
decoded
)
...
...
authhook/auth_on_subscribe.js
View file @
f78abcd2
...
...
@@ -38,10 +38,9 @@ module.exports = function (options = {}) {
checkRealDB
(
req
.
body
.
username
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
// 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
isShadow
=
require
(
'./utils/getTopic'
).
isShadow
if
(
isShadow
(
topic
))
{
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
'qos'
:
0
...
...
@@ -63,7 +62,35 @@ module.exports = function (options = {}) {
res
.
send
(
response
);
}
next
();
})
}
else
{
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
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
})
}
}
else
{
console
.
log
(
decoded
)
...
...
authhook/utils/getTopic.js
View file @
f78abcd2
...
...
@@ -16,4 +16,12 @@ function classifiedTopic(topic) {
}
else
if
(
topic
.
indexOf
(
'@client'
)
!==
-
1
)
{
return
'@client'
}
}
\ No newline at end of file
}
function
isShadow
(
topic
)
{
if
(
topic
.
indexOf
(
'@shadow'
)
!==
-
1
)
{
return
true
}
else
return
false
}
module
.
exports
.
isShadow
=
isShadow
\ 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