cookie expiry data from backend

This commit is contained in:
Jörn-Michael Miehe 2019-05-08 18:45:24 +02:00
parent 7c41b94a38
commit db53964007
3 changed files with 16 additions and 13 deletions

View file

@ -24,8 +24,8 @@ module.exports =
# login successful: start new session
logger.info "OK '#{request.body.login}'"
session.start user
.then (session_id) ->
resolve session_id
.then (cookie_data) ->
resolve cookie_data
.catch (err) ->
# login failed
@ -34,8 +34,8 @@ module.exports =
success: false
message: err
.then (session_id) ->
.then (cookie_data) ->
# login or resume successful
reply.send
success: true
message: session_id
message: JSON.stringify cookie_data

View file

@ -3,12 +3,12 @@ redis = (require 'redis')
crypto = (require 'crypto')
logger = (require 'logging').default 'session'
# expiry times in seconds
# expiry times in days
EXPIRY =
# games expire 1 week after creation
game: 1 * 60 * 60 * 24 * 7
game: 7
# logins expire 1 month after last action
login: 1 * 60 * 60 * 24 * 30
login: 30
class FFTCGSESSION
@ -29,9 +29,13 @@ class FFTCGSESSION
logger.debug 'digest', digest
# 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"
resolve digest
# return cookie data
resolve
value: digest
properties:
expires: EXPIRY.login
destroy: (digest) ->
new Promise (resolve, reject) =>
@ -46,7 +50,7 @@ class FFTCGSESSION
check: (digest) ->
new Promise (resolve, reject) =>
# refresh expiry timer on digest
@db.expire digest, EXPIRY.login, (err, res) =>
@db.expire digest, EXPIRY.login * 86400, (err, res) =>
if res == 0
reject null

View file

@ -51,11 +51,10 @@ export default {
password: this.password
})
.then(response => {
// this.$refs.form.reset()
console.log('login', response.data)
if (response.data.success) {
Cookies.set('session', response.data.message, { expires: 30 })
console.log('cookie', Cookies.get())
let cookie_data = JSON.parse(response.data.message)
Cookies.set('session', cookie_data.value, cookie_data.properties)
this.$router.push('about')
}
})