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
3d0afcba
Commit
3d0afcba
authored
Sep 17, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add role to flow
parent
d24dd439
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
2 deletions
+62
-2
authhook/auth_on_publish.js
+27
-0
authhook/auth_on_subscribe.js
+27
-1
authhook/index.js
+4
-0
authhook/on_deliver.js
+3
-0
authhook/on_publish.js
+1
-1
No files found.
authhook/auth_on_publish.js
View file @
3d0afcba
...
...
@@ -26,6 +26,12 @@ module.exports = function (options = {}) {
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
console
.
log
(
req
.
body
)
// checkRole
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
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
...
...
@@ -55,6 +61,27 @@ module.exports = function (options = {}) {
})
}
else
{
console
.
log
(
decoded
)
if
(
decoded
.
role
===
'realtimedb'
)
{
var
response
=
{
'result'
:
'ok'
}
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
{
res
.
send
({
"result"
:
"no"
});
...
...
authhook/auth_on_subscribe.js
View file @
3d0afcba
...
...
@@ -31,8 +31,12 @@ module.exports = function (options = {}) {
var
cachekey
=
'sub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
console
.
log
(
req
.
body
)
// checkRole
var
role
=
require
(
'./checkClientRole'
)
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
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
...
...
@@ -46,6 +50,7 @@ module.exports = function (options = {}) {
'result'
:
'ok'
,
'topics'
:
_topic
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
...
...
@@ -61,6 +66,27 @@ module.exports = function (options = {}) {
})
}
else
{
console
.
log
(
decoded
)
if
(
decoded
.
role
===
'realtimedb'
)
{
var
response
=
{
'result'
:
'ok'
}
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
{
res
.
send
({
"result"
:
"no"
});
...
...
authhook/index.js
View file @
3d0afcba
...
...
@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) {
server
.
post
(
'/authreg'
,
auth_on_register
);
server
.
post
(
'/authpub'
,
auth_on_publish
);
server
.
post
(
'/authsub'
,
auth_on_subscribe
);
server
.
post
(
'/onsub'
,
(
req
,
res
,
next
)
=>
{
console
.
log
(
req
.
body
)
res
.
send
(
''
)
})
server
.
post
(
'/ondeliver'
,
on_deliver
)
server
.
post
(
'/onpub'
,
on_publish
)
server
.
post
(
'/signRole'
,
signRole
)
...
...
authhook/on_deliver.js
View file @
3d0afcba
function
on_deliver
(
req
,
res
,
next
)
{
var
topics
=
beDesireTopic
(
req
.
body
.
topic
)
console
.
log
(
'----on_deliver-----'
)
console
.
log
(
req
.
body
)
console
.
log
(
topics
)
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
...
...
authhook/on_publish.js
View file @
3d0afcba
...
...
@@ -14,7 +14,7 @@ module.exports = function(options={}) {
console
.
log
(
'on_publish-------------'
);
console
.
log
(
req
.
body
);
}
console
.
log
(
req
.
body
)
var
topic
=
req
.
body
.
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
...
...
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