diff --git a/backend/routes/user/login.coffee b/backend/routes/user/login.coffee index 36e6595..c152fe1 100644 --- a/backend/routes/user/login.coffee +++ b/backend/routes/user/login.coffee @@ -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 diff --git a/backend/session.coffee b/backend/session.coffee index 56999cf..f915491 100644 --- a/backend/session.coffee +++ b/backend/session.coffee @@ -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 diff --git a/frontend/src/components/forms/Login.vue b/frontend/src/components/forms/Login.vue index f589f6d..3ced5fc 100644 --- a/frontend/src/components/forms/Login.vue +++ b/frontend/src/components/forms/Login.vue @@ -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') } })