classify session
This commit is contained in:
parent
d0180f3b38
commit
7221dd31af
1 changed files with 26 additions and 31 deletions
|
@ -11,7 +11,8 @@ EXPIRY =
|
||||||
login: 1 * 60 * 60 * 24 * 7 * 4
|
login: 1 * 60 * 60 * 24 * 7 * 4
|
||||||
|
|
||||||
|
|
||||||
FFTCGSESSION = () ->
|
class FFTCGSESSION
|
||||||
|
constructor: ->
|
||||||
@db = redis.createClient
|
@db = redis.createClient
|
||||||
host: 'redis'
|
host: 'redis'
|
||||||
port: 6379
|
port: 6379
|
||||||
|
@ -19,12 +20,8 @@ FFTCGSESSION = () ->
|
||||||
@db.on 'error', (err) ->
|
@db.on 'error', (err) ->
|
||||||
logger.error err.message
|
logger.error err.message
|
||||||
|
|
||||||
return
|
start: (data) ->
|
||||||
|
new Promise (resolve) =>
|
||||||
FFTCGSESSION::start = (data) ->
|
|
||||||
that = @
|
|
||||||
|
|
||||||
new Promise (resolve) ->
|
|
||||||
# hash data
|
# hash data
|
||||||
hmac = crypto.createHmac 'sha256', Math.random().toString()
|
hmac = crypto.createHmac 'sha256', Math.random().toString()
|
||||||
hmac.update (JSON.stringify data)
|
hmac.update (JSON.stringify data)
|
||||||
|
@ -32,20 +29,18 @@ FFTCGSESSION::start = (data) ->
|
||||||
logger.debug 'digest', digest
|
logger.debug 'digest', digest
|
||||||
|
|
||||||
# push (hash, data) into DB for the configured timespan
|
# push (hash, data) into DB for the configured timespan
|
||||||
that.db.setex digest, EXPIRY.login, (JSON.stringify data), (err) ->
|
@db.setex digest, EXPIRY.login, (JSON.stringify data), (err) ->
|
||||||
resolve digest
|
resolve digest
|
||||||
|
|
||||||
FFTCGSESSION::check = (digest) ->
|
check: (digest) ->
|
||||||
that = @
|
new Promise (resolve, reject) =>
|
||||||
|
|
||||||
new Promise (resolve, reject) ->
|
|
||||||
# refresh expiry timer on digest
|
# refresh expiry timer on digest
|
||||||
that.db.expire digest, EXPIRY.login, (err, res) ->
|
@db.expire digest, EXPIRY.login, (err, res) =>
|
||||||
if res == 0
|
if res == 0
|
||||||
reject null
|
reject null
|
||||||
|
|
||||||
else
|
else
|
||||||
that.db.get digest, (err, res) ->
|
@db.get digest, (err, res) ->
|
||||||
resolve JSON.parse res
|
resolve JSON.parse res
|
||||||
|
|
||||||
module.exports = FFTCGSESSION
|
module.exports = FFTCGSESSION
|
||||||
|
|
Reference in a new issue