route logging and login into usercp (game)
This commit is contained in:
parent
e0d6b818b8
commit
02b4a0a320
3 changed files with 31 additions and 7 deletions
|
@ -10,6 +10,17 @@ fftcgdb = new FFTCGDB path.resolve(__dirname, '../fftcg.db')
|
|||
|
||||
# create 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')
|
||||
|
||||
# register user
|
||||
|
@ -48,4 +59,23 @@ FFTCGROUTER.post '/login', (req, res) ->
|
|||
status: 'fail'
|
||||
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
|
||||
|
|
|
@ -24,13 +24,6 @@ app.use sessionMiddleware
|
|||
# routes
|
||||
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
|
||||
web = http.Server app
|
||||
socket = new FFTCGSOCKET web, sharedSession sessionMiddleware
|
||||
|
|
|
@ -49,6 +49,7 @@ $ ->
|
|||
if data.status == 'ok'
|
||||
that.fullReset()
|
||||
showAlert 'success', "successfully logged in '#{data.login}'"
|
||||
location.reload()
|
||||
|
||||
else
|
||||
switch data.text
|
||||
|
|
Reference in a new issue