X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=61c7f5cce5eed2f4cb84c1dd75d4e779ff9888b1;hb=ee078f73ebf00c2bb769de5e7502824b37b96535;hp=86306516878b1f68fd6d980ad9ea4e912692d053;hpb=808f638d7b86b8befcd9a5d3cd75b7e620d98206;p=lmno-server diff --git a/lmno.js b/lmno.js index 8630651..61c7f5c 100644 --- a/lmno.js +++ b/lmno.js @@ -136,14 +136,15 @@ app.get('/[a-zA-Z0-9]{4}', (request, response) => { }); /* LMNO middleware to lookup the game. */ -app.use('/empires/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { +app.use('/:engine([^/]+)/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { + const engine = request.params.engine; const game_id = request.params.game_id; const canon_id = lmno_canonize(game_id); /* Redirect user to page with the canonical ID in it. */ if (game_id !== canon_id) { - const new_url = request.originalUrl.replace("/empires/" + game_id, - "/empires/" + canon_id); + const new_url = request.originalUrl.replace(`/${engine}/${game_id}`, + `/${engine}/${canon_id}`); response.redirect(301, new_url); return; } @@ -180,6 +181,7 @@ function auth_admin(request, response, next) { app.get('/logout', (request, response) => { request.session.user = undefined; + request.session.destroy(); response.send("You are now logged out."); }); @@ -211,6 +213,16 @@ app.post('/login', async (request, response) => { return; }); +/* API to set uer profile information */ +app.put('/profile', (request, response) => { + const nickname = request.body.nickname; + if (nickname) { + request.session.nickname = nickname; + request.session.save(); + } + response.send(); +}); + /* An admin page (only available to admin users, of course) */ app.get('/admin/', auth_admin, (request, response) => { let active = [];