less stuff into Redis, /user/info from sqlite
This commit is contained in:
parent
cbc27f1706
commit
6dcb5a4963
2 changed files with 37 additions and 10 deletions
|
@ -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
|
||||||
|
|
|
@ -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,12 +12,20 @@ module.exports =
|
||||||
|
|
||||||
handler: (request, reply) ->
|
handler: (request, reply) ->
|
||||||
session.check request.body.session ? ""
|
session.check request.body.session ? ""
|
||||||
.then (user) ->
|
.then (userid) ->
|
||||||
# active session found
|
# active session found, get associated user
|
||||||
logger.debug "OK '#{user.login}' got info"
|
fftcgdb.get (userid)
|
||||||
reply.send
|
.then (user) ->
|
||||||
success: true
|
logger.debug "OK '#{user.login}' got info"
|
||||||
user: user
|
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 ->
|
.catch ->
|
||||||
# no session found
|
# no session found
|
||||||
|
|
Reference in a new issue