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 if res == true
logger.debug "login: OK '#{row.login}'" logger.debug "login: OK '#{row.login}'"
# login successful # login successful
resolve resolve row.user
user: row.user
login: row.login
settings: row.settings
else else
logger.debug "login: FAIL password for '#{login}'" logger.debug "login: FAIL password for '#{login}'"
@ -150,6 +147,26 @@ class FFTCGDB
.catch -> .catch ->
reject messages.empty 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) -> addDeck: (user, deckCards) ->
new Promise (resolve, reject) => new Promise (resolve, reject) =>
# try creating row in decks table # try creating row in decks table

View file

@ -2,6 +2,8 @@ logger = (require 'logging').default '/user/info'
# session storage (volatile data) # session storage (volatile data)
session = (require '../../session') session = (require '../../session')
# fftcg.db (persistent data)
fftcgdb = (require '../../db')
module.exports = module.exports =
url: '/user/info' url: '/user/info'
@ -10,13 +12,21 @@ module.exports =
handler: (request, reply) -> handler: (request, reply) ->
session.check request.body.session ? "" session.check request.body.session ? ""
.then (userid) ->
# active session found, get associated user
fftcgdb.get (userid)
.then (user) -> .then (user) ->
# active session found
logger.debug "OK '#{user.login}' got info" logger.debug "OK '#{user.login}' got info"
reply.send reply.send
success: true success: true
user: user user: user
.catch (err) ->
# couldnt get user details
logger.warn "FAIL '#{err}' for user id '#{userid}'"
reply.send
success: false
.catch -> .catch ->
# no session found # no session found
logger.info "FAIL '#{request.body.session}' session not found" logger.info "FAIL '#{request.body.session}' session not found"