From e360c3d487e10892b5fb7add3051bfd4dd76b6f3 Mon Sep 17 00:00:00 2001 From: Maxime Augier Date: Sun, 16 Feb 2025 00:36:26 +0100 Subject: [PATCH] Use JSON post for answer setup --- choices.html | 46 ++++++++++++++++++++++++++++++++-------------- index.js | 8 +++++--- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/choices.html b/choices.html index e35ca24..ce543dc 100644 --- a/choices.html +++ b/choices.html @@ -13,24 +13,26 @@ -
-
- Question: - -
-
- - - -
- - - -
+ +
+ Question: + +
+
+ + + +
+ + + + \ No newline at end of file diff --git a/index.js b/index.js index 23b31a5..7b61552 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,6 @@ app.use(session({ saveUninitialized: false, secret: randomUUID(), })) -app.use(formidable()); app.get('/', (req, res) => { res.sendFile(page("index.html")); @@ -59,6 +58,7 @@ app.get('/login', (req,res) => { res.sendFile(page("login.html")); }) +app.use('/login', formidable()) app.post('/login', (req, res) => { if (req.fields.password !== admin_password) { return res.sendStatus(403); @@ -67,14 +67,16 @@ app.post('/login', (req, res) => { res.redirect('/choices'); }) + app.use('/choices', admin_only); +app.use('/choices', express.json()) app.get('/choices', (req, res) => { res.sendFile(page("choices.html")); }) app.post('/choices', (req, res) => { - console.log(JSON.stringify(req.fields)); - set_choices(req.fields.choice, req.fields.question); + console.log(JSON.stringify(req.body)); + set_choices(req.body.choices, req.body.question); res.redirect("/#abstain") });