routes for basic user mgmt
This commit is contained in:
parent
d9eb9796b1
commit
e78570f298
4 changed files with 49 additions and 41 deletions
|
@ -1,5 +1,5 @@
|
||||||
# node libraries
|
# node libraries
|
||||||
#(require 'debug').enable 'routes'
|
(require 'debug').enable 'routes'
|
||||||
logger = (require 'logging').default 'routes'
|
logger = (require 'logging').default 'routes'
|
||||||
path = (require 'path')
|
path = (require 'path')
|
||||||
|
|
||||||
|
@ -63,12 +63,13 @@ module.exports = [
|
||||||
schema: JSONSCHEMA.user()
|
schema: JSONSCHEMA.user()
|
||||||
|
|
||||||
handler: (request, reply) ->
|
handler: (request, reply) ->
|
||||||
fftcgdb.register request.body.login, request.body.password
|
fftcgdb.register(request.body.login, request.body.password)
|
||||||
.then (user) ->
|
.then (user) ->
|
||||||
logger.info "OK registration '#{request.body.login}'"
|
logger.info "OK registration '#{request.body.login}'"
|
||||||
reply.send
|
reply.send
|
||||||
success: true
|
success: true
|
||||||
user: user
|
user: user
|
||||||
|
return
|
||||||
|
|
||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
logger.debug "FAIL registration '#{request.body.login}'"
|
logger.debug "FAIL registration '#{request.body.login}'"
|
||||||
|
@ -87,6 +88,7 @@ module.exports = [
|
||||||
new Promise (resolve) ->
|
new Promise (resolve) ->
|
||||||
session.check session_id
|
session.check session_id
|
||||||
.then (user) ->
|
.then (user) ->
|
||||||
|
# active session found
|
||||||
logger.debug "OK '#{user.login}' resumed session '#{session_id}'"
|
logger.debug "OK '#{user.login}' resumed session '#{session_id}'"
|
||||||
resolve user
|
resolve user
|
||||||
|
|
||||||
|
@ -101,12 +103,14 @@ module.exports = [
|
||||||
resolve user
|
resolve user
|
||||||
|
|
||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
|
# login failed
|
||||||
logger.info "FAIL login for '#{request.body.login}'"
|
logger.info "FAIL login for '#{request.body.login}'"
|
||||||
reply.send
|
reply.send
|
||||||
success: false
|
success: false
|
||||||
msg: err
|
err: err
|
||||||
|
|
||||||
.then (user) ->
|
.then (user) ->
|
||||||
|
# tell about the user who logged in
|
||||||
reply.send
|
reply.send
|
||||||
success: true
|
success: true
|
||||||
user: user
|
user: user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# node libraries
|
# node libraries
|
||||||
|
# (require 'debug').enable 'FFTCG'
|
||||||
logger = (require 'logging').default 'FFTCG'
|
logger = (require 'logging').default 'FFTCG'
|
||||||
fastify = (require 'fastify') logger: logger
|
fastify = (require 'fastify')
|
||||||
|
logger: level: 'warn'
|
||||||
path = (require 'path')
|
path = (require 'path')
|
||||||
|
|
||||||
# my libraries
|
# my libraries
|
||||||
|
@ -21,9 +23,11 @@ fastify.ready()
|
||||||
logger.error err
|
logger.error err
|
||||||
process.exit 1
|
process.exit 1
|
||||||
|
|
||||||
|
fastify.addHook 'onRequest', (req, res, next) ->
|
||||||
|
logger.debug 'requested', req.url
|
||||||
|
next()
|
||||||
|
|
||||||
for route in routes
|
fastify.route route for route in routes
|
||||||
fastify.route route
|
|
||||||
|
|
||||||
fastify.listen 3001, '0.0.0.0'
|
fastify.listen 3001, '0.0.0.0'
|
||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
|
|
|
@ -5,7 +5,7 @@ logger = (require 'logging').default 'session'
|
||||||
|
|
||||||
# expiry times in seconds
|
# expiry times in seconds
|
||||||
EXPIRY =
|
EXPIRY =
|
||||||
# games expire 1 week after last action
|
# games expire 1 week after creation
|
||||||
game: 1 * 60 * 60 * 24 * 7
|
game: 1 * 60 * 60 * 24 * 7
|
||||||
# logins expire 1 month after last action
|
# logins expire 1 month after last action
|
||||||
login: 1 * 60 * 60 * 24 * 7 * 4
|
login: 1 * 60 * 60 * 24 * 7 * 4
|
||||||
|
|
|
@ -345,10 +345,10 @@ chalk@^2.0.1, chalk@^2.4.1:
|
||||||
escape-string-regexp "^1.0.5"
|
escape-string-regexp "^1.0.5"
|
||||||
supports-color "^5.3.0"
|
supports-color "^5.3.0"
|
||||||
|
|
||||||
chokidar@^2.0.4:
|
chokidar@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.0.tgz#5fcb70d0b28ebe0867eb0f09d5f6a08f29a1efa0"
|
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.1.tgz#adc39ad55a2adf26548bd2afa048f611091f9184"
|
||||||
integrity sha512-5t6G2SH8eO6lCvYOoUpaRnF5Qfd//gd7qJAkwRUw9qlGVkiQ13uwQngqbWWaurOsaAm9+kUGbITADxt6H0XFNQ==
|
integrity sha512-gfw3p2oQV2wEt+8VuMlNsPjCxDxvvgnm/kz+uATu805mWVF8IJN7uz9DN7iBz+RMJISmiVbCOBFs9qBGMjtPfQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
anymatch "^2.0.0"
|
anymatch "^2.0.0"
|
||||||
async-each "^1.0.1"
|
async-each "^1.0.1"
|
||||||
|
@ -1629,11 +1629,11 @@ node-pre-gyp@^0.11.0:
|
||||||
tar "^4"
|
tar "^4"
|
||||||
|
|
||||||
nodemon@^1.18.9:
|
nodemon@^1.18.9:
|
||||||
version "1.18.9"
|
version "1.18.10"
|
||||||
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.18.9.tgz#90b467efd3b3c81b9453380aeb2a2cba535d0ead"
|
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.18.10.tgz#3ba63f64eb4c283cf3e4f75f30817e9d4f393afe"
|
||||||
integrity sha512-oj/eEVTEI47pzYAjGkpcNw0xYwTl4XSTUQv2NPQI6PpN3b75PhpuYk3Vb3U80xHCyM2Jm+1j68ULHXl4OR3Afw==
|
integrity sha512-we51yBb1TfEvZamFchRgcfLbVYgg0xlGbyXmOtbBzDwxwgewYS/YbZ5tnlnsH51+AoSTTsT3A2E/FloUbtH8cQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
chokidar "^2.0.4"
|
chokidar "^2.1.0"
|
||||||
debug "^3.1.0"
|
debug "^3.1.0"
|
||||||
ignore-by-default "^1.0.1"
|
ignore-by-default "^1.0.1"
|
||||||
minimatch "^3.0.4"
|
minimatch "^3.0.4"
|
||||||
|
|
Reference in a new issue