cookie expiry data from backend
This commit is contained in:
parent
7c41b94a38
commit
db53964007
3 changed files with 16 additions and 13 deletions
|
@ -24,8 +24,8 @@ module.exports =
|
||||||
# login successful: start new session
|
# login successful: start new session
|
||||||
logger.info "OK '#{request.body.login}'"
|
logger.info "OK '#{request.body.login}'"
|
||||||
session.start user
|
session.start user
|
||||||
.then (session_id) ->
|
.then (cookie_data) ->
|
||||||
resolve session_id
|
resolve cookie_data
|
||||||
|
|
||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
# login failed
|
# login failed
|
||||||
|
@ -34,8 +34,8 @@ module.exports =
|
||||||
success: false
|
success: false
|
||||||
message: err
|
message: err
|
||||||
|
|
||||||
.then (session_id) ->
|
.then (cookie_data) ->
|
||||||
# login or resume successful
|
# login or resume successful
|
||||||
reply.send
|
reply.send
|
||||||
success: true
|
success: true
|
||||||
message: session_id
|
message: JSON.stringify cookie_data
|
||||||
|
|
|
@ -3,12 +3,12 @@ redis = (require 'redis')
|
||||||
crypto = (require 'crypto')
|
crypto = (require 'crypto')
|
||||||
logger = (require 'logging').default 'session'
|
logger = (require 'logging').default 'session'
|
||||||
|
|
||||||
# expiry times in seconds
|
# expiry times in days
|
||||||
EXPIRY =
|
EXPIRY =
|
||||||
# games expire 1 week after creation
|
# games expire 1 week after creation
|
||||||
game: 1 * 60 * 60 * 24 * 7
|
game: 7
|
||||||
# logins expire 1 month after last action
|
# logins expire 1 month after last action
|
||||||
login: 1 * 60 * 60 * 24 * 30
|
login: 30
|
||||||
|
|
||||||
|
|
||||||
class FFTCGSESSION
|
class FFTCGSESSION
|
||||||
|
@ -29,9 +29,13 @@ class FFTCGSESSION
|
||||||
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
|
||||||
@db.setex digest, EXPIRY.login, (JSON.stringify data), (err) ->
|
@db.setex digest, EXPIRY.login * 86400, (JSON.stringify data), (err) ->
|
||||||
logger.info "OK '#{digest}' created"
|
logger.info "OK '#{digest}' created"
|
||||||
resolve digest
|
# return cookie data
|
||||||
|
resolve
|
||||||
|
value: digest
|
||||||
|
properties:
|
||||||
|
expires: EXPIRY.login
|
||||||
|
|
||||||
destroy: (digest) ->
|
destroy: (digest) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
|
@ -46,7 +50,7 @@ class FFTCGSESSION
|
||||||
check: (digest) ->
|
check: (digest) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
# refresh expiry timer on digest
|
# refresh expiry timer on digest
|
||||||
@db.expire digest, EXPIRY.login, (err, res) =>
|
@db.expire digest, EXPIRY.login * 86400, (err, res) =>
|
||||||
if res == 0
|
if res == 0
|
||||||
reject null
|
reject null
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,10 @@ export default {
|
||||||
password: this.password
|
password: this.password
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// this.$refs.form.reset()
|
|
||||||
console.log('login', response.data)
|
console.log('login', response.data)
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
Cookies.set('session', response.data.message, { expires: 30 })
|
let cookie_data = JSON.parse(response.data.message)
|
||||||
console.log('cookie', Cookies.get())
|
Cookies.set('session', cookie_data.value, cookie_data.properties)
|
||||||
this.$router.push('about')
|
this.$router.push('about')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Reference in a new issue