From 6dcb5a4963facf61a1989138f55cb90cdfadb66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 9 May 2019 18:03:35 +0200 Subject: [PATCH] less stuff into Redis, /user/info from sqlite --- backend/db.coffee | 25 +++++++++++++++++++++---- backend/routes/user/info.coffee | 22 ++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/backend/db.coffee b/backend/db.coffee index 686aec5..f1cbbb3 100644 --- a/backend/db.coffee +++ b/backend/db.coffee @@ -138,10 +138,7 @@ class FFTCGDB if res == true logger.debug "login: OK '#{row.login}'" # login successful - resolve - user: row.user - login: row.login - settings: row.settings + resolve row.user else logger.debug "login: FAIL password for '#{login}'" @@ -150,6 +147,26 @@ class FFTCGDB .catch -> reject messages.empty + get: (user) -> + new Promise (resolve, reject) => + # get users table row + stmt = @db.prepare 'SELECT * FROM users WHERE user = ?' + stmt.get [user], (err, row) => + stmt.finalize() + if err + logger.warn "get: FAIL db '#{err.code}' for '#{user}'" + reject messages.db + + else if not row + logger.debug "get: FAIL nonexistent '#{user}'" + reject messages.noexists # user doesnt exist + + else + resolve + user: row.user + login: row.login + settings: row.settings + addDeck: (user, deckCards) -> new Promise (resolve, reject) => # try creating row in decks table diff --git a/backend/routes/user/info.coffee b/backend/routes/user/info.coffee index a648538..7a319e8 100644 --- a/backend/routes/user/info.coffee +++ b/backend/routes/user/info.coffee @@ -2,6 +2,8 @@ logger = (require 'logging').default '/user/info' # session storage (volatile data) session = (require '../../session') +# fftcg.db (persistent data) +fftcgdb = (require '../../db') module.exports = url: '/user/info' @@ -10,12 +12,20 @@ module.exports = 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 + .then (userid) -> + # active session found, get associated user + fftcgdb.get (userid) + .then (user) -> + logger.debug "OK '#{user.login}' got info" + reply.send + success: true + user: user + + .catch (err) -> + # couldnt get user details + logger.warn "FAIL '#{err}' for user id '#{userid}'" + reply.send + success: false .catch -> # no session found