route logging and login into usercp (game)

This commit is contained in:
Jörn-Michael Miehe 2018-12-27 00:16:59 +01:00
parent e0d6b818b8
commit 02b4a0a320
3 changed files with 31 additions and 7 deletions

View file

@ -10,6 +10,17 @@ fftcgdb = new FFTCGDB path.resolve(__dirname, '../fftcg.db')
# create router # create router
FFTCGROUTER = express.Router() FFTCGROUTER = express.Router()
# request logging
FFTCGROUTER.use (req, res, next) ->
if req.session.user
console.log "[FFTCG] user '#{req.session.user.login}' requested '#{req.url}'"
else
console.log "[FFTCG] requested '#{req.url}'"
next()
# static content
FFTCGROUTER.use express.static path.resolve(__dirname, '../public_html') FFTCGROUTER.use express.static path.resolve(__dirname, '../public_html')
# register user # register user
@ -48,4 +59,23 @@ FFTCGROUTER.post '/login', (req, res) ->
status: 'fail' status: 'fail'
text: err text: err
# Templates
FFTCGROUTER.get '/:template.html', (req, res) ->
if req.session.user and req.params.template == 'index'
return res.redirect '/game.html'
# render requested template
res.render (req.params.template + '.pug'), (err, html) ->
# redirect invalid requests to index
if err
return res.redirect '/index.html'
# actual response
res.send html
# default route
FFTCGROUTER.use (req, res) ->
return res.redirect '/index.html'
module.exports = FFTCGROUTER module.exports = FFTCGROUTER

View file

@ -24,13 +24,6 @@ app.use sessionMiddleware
# routes # routes
app.use FFTCGROUTER app.use FFTCGROUTER
# Templates
app.set 'view engine', 'pug'
app.get '/:template.html', (req, res) ->
if req.session.user
console.log "[FFTCG] user is '#{req.session.user.login}'"
res.render (req.params.template + '.pug')
# socket.io # socket.io
web = http.Server app web = http.Server app
socket = new FFTCGSOCKET web, sharedSession sessionMiddleware socket = new FFTCGSOCKET web, sharedSession sessionMiddleware

View file

@ -49,6 +49,7 @@ $ ->
if data.status == 'ok' if data.status == 'ok'
that.fullReset() that.fullReset()
showAlert 'success', "successfully logged in '#{data.login}'" showAlert 'success', "successfully logged in '#{data.login}'"
location.reload()
else else
switch data.text switch data.text