From feeece281fad0412ad08c10a2969866d079d0789 Mon Sep 17 00:00:00 2001
From: clement callaert
Date: Mon, 6 Nov 2023 01:46:03 +0100
Subject: [PATCH] login with email
---
routes/auth.js | 8 +++++---
routes/demo.js | 3 ++-
routes/posts.js | 7 +++++++
views/adminPage.ejs | 30 ++++++++++++++++++++++++++++--
views/hotLine.ejs | 18 +++++++++++-------
5 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/routes/auth.js b/routes/auth.js
index 13ff679..e51283f 100644
--- a/routes/auth.js
+++ b/routes/auth.js
@@ -172,14 +172,16 @@ router.post('/logout', function (req, res) {
res.redirect('/');
});
-router.post('mettreAdmin', async function (req,res) {
- const enteredNomDutilisateur = res.body.utilisateurs;
+router.post('/mettreAdmin', async function (req,res) {
+ const enteredNomDutilisateur = req.body.utilisateurs;
await db.getDb().collection('users').updateOne({nom_dutilisateur: enteredNomDutilisateur}, {$set: {isAdmin: true}})
+ return res.redirect('/admin')
})
router.post('/supprAdmin', async function (req,res) {
- const enteredNomDutilisateur = res.body.utilisateurs;
+ const enteredNomDutilisateur = req.body.utilisateurs;
await db.getDb().collection('users').updateOne({nom_dutilisateur: enteredNomDutilisateur}, {$set: {isAdmin: false}})
+ return res.redirect('/admin')
})
module.exports = router
\ No newline at end of file
diff --git a/routes/demo.js b/routes/demo.js
index a54cd51..2bf5353 100644
--- a/routes/demo.js
+++ b/routes/demo.js
@@ -30,7 +30,8 @@ router.get('/admin', async function (req, res) {
const users = await db.getDb().collection('users').find().toArray();
const postData = await db.getDb().collection('posts').find().toArray();
const resData = await db.getDb().collection('res').find().toArray();
- res.render('adminPage', {users: users, postData: postData, resData:resData});
+ const commandeData = await db.getDb().collection('commandes').find().toArray();
+ res.render('adminPage', {users: users, postData: postData, resData:resData, commandeData: commandeData});
})
diff --git a/routes/posts.js b/routes/posts.js
index 836a078..c123501 100644
--- a/routes/posts.js
+++ b/routes/posts.js
@@ -111,5 +111,12 @@ router.post('/supprimerPost/:id', async function (req, res) {
return res.redirect('/admin');
});
+router.post('/isFinish/:id', async function (req, res) {
+ const postId = req.params.id;
+ const ObjectID = mongodb.ObjectId;
+ const postObjectId = new ObjectID(postId);
+ await db.getDb().collection('commandes').updateOne({ _id: postObjectId }, {$set: {isFinish: true}});
+ return res.redirect('/admin');
+})
module.exports = router;
\ No newline at end of file
diff --git a/views/adminPage.ejs b/views/adminPage.ejs
index b8aa497..4a1752d 100644
--- a/views/adminPage.ejs
+++ b/views/adminPage.ejs
@@ -14,7 +14,7 @@
Faire de quelqu'un un admin
-
<% } %>
<% }) %>
+ <% if (toutesLesCommandesSontTerminees) { %>
+
+ Pas encore de commande
+
+ <% } %>
+
@@ -89,7 +93,7 @@
Récompense : <%= post.recompense %>
- statue : Accepté
+ statut : Accepté
<% } else {%>
@@ -102,7 +106,7 @@
Récompense : <%= post.recompense %>
- statue : en attente
+ statut : en attente