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
742e2089
Commit
742e2089
authored
Dec 04, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add handler error from redis
parent
cefb2042
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
15 deletions
+61
-15
authhook/auth_on_publish.js
+5
-0
authhook/auth_on_register.js
+20
-15
authhook/redis/on_message.js
+12
-0
authhook/redis/on_offline.js
+12
-0
authhook/redis/on_register.js
+12
-0
No files found.
authhook/auth_on_publish.js
View file @
742e2089
...
@@ -61,8 +61,13 @@ module.exports = function (options = {}) {
...
@@ -61,8 +61,13 @@ module.exports = function (options = {}) {
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
response
.
modifiers
.
payload
=
Buffer
.
from
(
req
.
body
.
client_id
).
toString
(
'base64'
);
}
}
// save on redis before send response
// save on redis before send response
try
{
on_message_redis
(
req
.
body
.
client_id
,
req
.
body
.
payload
,
topic
)
on_message_redis
(
req
.
body
.
client_id
,
req
.
body
.
payload
,
topic
)
res
.
send
(
response
);
res
.
send
(
response
);
}
catch
(
e
)
{
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
}
next
();
next
();
}
}
else
{
else
{
...
...
authhook/auth_on_register.js
View file @
742e2089
...
@@ -62,28 +62,33 @@ module.exports = function (options = {}) {
...
@@ -62,28 +62,33 @@ module.exports = function (options = {}) {
}
}
var
cachekey
=
'auth:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
req
.
body
.
password
;
var
cachekey
=
'auth:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
req
.
body
.
password
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
//
if (typeof (authstatus) == 'undefined') {
// cache missed
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
req
.
body
.
password
,
function
(
result
)
{
// authCheck(req.body.client_id, req.body.username, req.body.password, function (result) {
cache
.
set
(
cachekey
,
result
);
// cache.set(cachekey, result);
if
(
result
)
{
// if (result) {
try
{
on_register_redis
(
req
.
body
.
client_id
)
on_register_redis
(
req
.
body
.
client_id
)
res
.
send
({
result
:
'ok'
});
res
.
send
({
result
:
'ok'
});
}
else
{
}
catch
(
e
)
{
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
}
}
// } else {
// res.send({ result: { error: 'not allowed' } });
// }
// const util = require('util')
// const util = require('util')
// console.log(util.inspect(status, false, null, true))
// console.log(util.inspect(status, false, null, true))
});
//
});
}
//
}
else
{
//
else {
if
(
authstatus
)
{
//
if (authstatus) {
on_register_redis
(
req
.
body
.
client_id
)
//
on_register_redis(req.body.client_id)
res
.
send
({
result
:
'ok'
});
//
res.send({ result: 'ok' });
}
else
{
//
} else {
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
//
res.send({ result: { error: 'not allowed' } });
}
//
}
}
//
}
next
();
next
();
}
}
else
{
else
{
...
...
authhook/redis/on_message.js
View file @
742e2089
...
@@ -21,6 +21,18 @@ function on_message_redis(deviceid, payload, topic) { // first time to access on
...
@@ -21,6 +21,18 @@ function on_message_redis(deviceid, payload, topic) { // first time to access on
}
}
module
.
exports
.
on_message_redis
=
on_message_redis
module
.
exports
.
on_message_redis
=
on_message_redis
redis
.
on
(
"error"
,
(
error
)
=>
{
console
.
log
(
"Redis connection error"
,
error
);
});
redis
.
on
(
'reconnecting'
,
function
reconnecting
()
{
console
.
log
(
'Connection reestablished'
);
});
redis
.
on
(
'connect'
,
function
connect
()
{
console
.
log
(
'connecting'
);
});
function
setValue
(
deviceid
,
payload
,
topic
)
{
function
setValue
(
deviceid
,
payload
,
topic
)
{
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
keys
=
'deviceid:'
+
deviceid
var
keys
=
'deviceid:'
+
deviceid
...
...
authhook/redis/on_offline.js
View file @
742e2089
...
@@ -12,6 +12,18 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
...
@@ -12,6 +12,18 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
}
module
.
exports
.
on_offline_redis
=
on_offline_redis
module
.
exports
.
on_offline_redis
=
on_offline_redis
redis
.
on
(
"error"
,
(
error
)
=>
{
console
.
log
(
"Redis connection error"
,
error
);
});
redis
.
on
(
'reconnecting'
,
function
reconnecting
()
{
console
.
log
(
'Connection reestablished'
);
});
redis
.
on
(
'connect'
,
function
connect
()
{
console
.
log
(
'connecting'
);
});
function
setValue
(
deviceid
)
{
function
setValue
(
deviceid
)
{
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
keys
=
'deviceid:'
+
deviceid
var
keys
=
'deviceid:'
+
deviceid
...
...
authhook/redis/on_register.js
View file @
742e2089
...
@@ -14,6 +14,18 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
...
@@ -14,6 +14,18 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
}
}
module
.
exports
.
on_register_redis
=
on_register_redis
module
.
exports
.
on_register_redis
=
on_register_redis
redis
.
on
(
"error"
,
(
error
)
=>
{
console
.
log
(
"Redis connection error"
,
error
);
});
redis
.
on
(
'reconnecting'
,
function
reconnecting
()
{
console
.
log
(
'Connection reestablished'
);
});
redis
.
on
(
'connect'
,
function
connect
()
{
console
.
log
(
'connecting'
);
});
function
setValue
(
deviceid
)
{
function
setValue
(
deviceid
)
{
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
dateNow
=
Math
.
floor
(
Date
.
now
()
/
1000
)
var
keys
=
'deviceid:'
+
deviceid
var
keys
=
'deviceid:'
+
deviceid
...
...
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