From e64f5dbabf75143a7298ab5f7d61e60ae69b417c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 9 May 2019 14:31:54 +0200 Subject: [PATCH] /user/info route --- backend/routes/user/info.coffee | 24 ++++++++++++++++++++++++ backend/routes/user/info.schema.coffee | 24 ++++++++++++++++++++++++ backend/server.coffee | 2 ++ backend/session.coffee | 2 +- frontend/src/views/UserCP.vue | 6 +++--- 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 backend/routes/user/info.coffee create mode 100644 backend/routes/user/info.schema.coffee diff --git a/backend/routes/user/info.coffee b/backend/routes/user/info.coffee new file mode 100644 index 0000000..ba5abdf --- /dev/null +++ b/backend/routes/user/info.coffee @@ -0,0 +1,24 @@ +logger = (require 'logging').default 'info' + +# session storage (volatile data) +session = (require '../../session') + +module.exports = + url: '/user/info' + method: 'POST' + schema: (require './info.schema') + + handler: (request, reply) -> + session.check request.body.session ? "" + .then (user) -> + # active session found + logger.debug "OK '#{user.login}' got info" + reply.send + success: true + user: user + + .catch -> + # no session found + logger.info "FAIL '#{request.body.session}' session not found" + reply.send + success: false diff --git a/backend/routes/user/info.schema.coffee b/backend/routes/user/info.schema.coffee new file mode 100644 index 0000000..ed82e65 --- /dev/null +++ b/backend/routes/user/info.schema.coffee @@ -0,0 +1,24 @@ +module.exports = + body: + session: type: 'string' + response: + 200: + type: 'object' + required: ['success'] + properties: + success: type: 'boolean' + user: + type: 'object' + required: ['user', 'login', 'settings'] + properties: + user: type: 'integer' + login: type: 'string' + settings: type: 'string' + # user is required iff success + if: + properties: + success: + const: true + then: + required: ['user'] + else: true diff --git a/backend/server.coffee b/backend/server.coffee index eef08d7..f3c1ab1 100644 --- a/backend/server.coffee +++ b/backend/server.coffee @@ -14,6 +14,8 @@ fastify.route (require "./routes/#{route}") for route in [ 'test' # log in user 'user/login' + # user info + 'user/info' # log out user 'user/logout' # register user diff --git a/backend/session.coffee b/backend/session.coffee index f915491..d3e61ba 100644 --- a/backend/session.coffee +++ b/backend/session.coffee @@ -57,6 +57,6 @@ class FFTCGSESSION else @db.get digest, (err, res) -> logger.info "OK '#{digest}' resumed" - resolve digest + resolve (JSON.parse res) module.exports = new FFTCGSESSION diff --git a/frontend/src/views/UserCP.vue b/frontend/src/views/UserCP.vue index ccedc42..c763cc0 100644 --- a/frontend/src/views/UserCP.vue +++ b/frontend/src/views/UserCP.vue @@ -2,7 +2,7 @@
-

user logged in: {{ user }}

+

user logged in: {{ user.login }}

Logout @@ -45,12 +45,12 @@ export default { mounted() { axios - .post('/user/login', { + .post('/user/info', { session: Cookies.get('session') }) .then(response => { if (response.data.success) { - this.user = response.data.message + this.user = response.data.user } else { this.goHome() }