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
99c5a125
Commit
99c5a125
authored
Dec 04, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add check status before save redis
parent
742e2089
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
25 deletions
+27
-25
authhook/auth_on_register.js
+17
-20
authhook/redis/on_offline.js
+5
-2
authhook/redis/on_register.js
+5
-3
No files found.
authhook/auth_on_register.js
View file @
99c5a125
...
@@ -62,11 +62,10 @@ module.exports = function (options = {}) {
...
@@ -62,11 +62,10 @@ 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
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
{
try
{
on_register_redis
(
req
.
body
.
client_id
)
on_register_redis
(
req
.
body
.
client_id
)
res
.
send
({
result
:
'ok'
});
res
.
send
({
result
:
'ok'
});
...
@@ -74,21 +73,19 @@ module.exports = function (options = {}) {
...
@@ -74,21 +73,19 @@ module.exports = function (options = {}) {
catch
(
e
)
{
catch
(
e
)
{
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
}
}
// } else {
}
else
{
// res.send({ result: { error: 'not allowed' } });
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
// }
}
// const util = require('util')
});
// console.log(util.inspect(status, false, null, true))
}
// });
else
{
// }
if
(
authstatus
)
{
// else {
on_register_redis
(
req
.
body
.
client_id
)
// if (authstatus) {
res
.
send
({
result
:
'ok'
});
// on_register_redis(req.body.client_id)
}
else
{
// res.send({ result: 'ok' });
res
.
send
({
result
:
{
error
:
'not allowed'
}
});
// } else {
}
// res.send({ result: { error: 'not allowed' } });
}
// }
// }
next
();
next
();
}
}
else
{
else
{
...
...
authhook/redis/on_offline.js
View file @
99c5a125
...
@@ -6,8 +6,11 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
...
@@ -6,8 +6,11 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
}
else
{
else
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
)
var
status
=
redis
.
hget
(
information
.
keys
,
'status'
)
deviceUsageCount
()
if
(
status
!==
false
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
)
deviceUsageCount
()
}
}
}
}
}
module
.
exports
.
on_offline_redis
=
on_offline_redis
module
.
exports
.
on_offline_redis
=
on_offline_redis
...
...
authhook/redis/on_register.js
View file @
99c5a125
...
@@ -7,9 +7,11 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
...
@@ -7,9 +7,11 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
else
{
else
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
console
.
log
(
information
.
keys
)
var
status
=
redis
.
hget
(
information
.
keys
,
'status'
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
)
if
(
status
!==
true
)
{
deviceUsageCount
()
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
)
deviceUsageCount
()
}
}
}
}
}
module
.
exports
.
on_register_redis
=
on_register_redis
module
.
exports
.
on_register_redis
=
on_register_redis
...
...
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