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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
21 deletions
+23
-21
authhook/auth_on_register.js
+17
-20
authhook/redis/on_offline.js
+3
-0
authhook/redis/on_register.js
+3
-1
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,9 +6,12 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
...
@@ -6,9 +6,12 @@ function on_offline_redis(deviceid) { // first time to access on authhook auth_o
}
}
else
{
else
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
var
status
=
redis
.
hget
(
information
.
keys
,
'status'
)
if
(
status
!==
false
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
)
deviceUsageCount
()
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,10 +7,12 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
...
@@ -7,10 +7,12 @@ 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'
)
if
(
status
!==
true
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
)
deviceUsageCount
()
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