less stuff into Redis, /user/info from sqlite

This commit is contained in:
Jörn-Michael Miehe 2019-05-09 18:03:35 +02:00
parent cbc27f1706
commit 6dcb5a4963
2 changed files with 37 additions and 10 deletions

View file

@ -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

View file

@ -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,13 +12,21 @@ module.exports =
handler: (request, reply) ->
session.check request.body.session ? ""
.then (userid) ->
# active session found, get associated user
fftcgdb.get (userid)
.then (user) ->
# active session found
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
logger.info "FAIL '#{request.body.session}' session not found"