Metzploreur/routes/demo.js
2023-11-06 01:46:03 +01:00

62 lines
1.5 KiB
JavaScript

const express = require('express');
const bcrypt = require('bcryptjs');
const db = require('../data/database');
const Post = require('../models/post')
const router = express.Router();
router.get('/', function (req, res) {
res.render('index');
});
router.get('/profile', function(req, res) {
if (!req.session.isAuthenticated) {
return res.status(401).render('401');
}
res.render('profile');
});
router.get('/admin', async function (req, res) {
if (!req.session.isAuthenticated) {
return res.status(401).render('401');
}
const user = await db.getDb().collection('users').findOne({_id: req.session.user.id})
if (!user || !user.isAdmin) {
return res.status(403).render('403');
}
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();
const commandeData = await db.getDb().collection('commandes').find().toArray();
res.render('adminPage', {users: users, postData: postData, resData:resData, commandeData: commandeData});
})
router.get('/contact', function (req, res) {
res.render('futur')
})
router.get('/sports', function (req,res) {
res.render('futur')
})
router.get('/services', function (req,res) {
res.render('futur')
})
router.get('/team', function (req,res) {
res.render('futur')
})
router.get('/a-propos', function (req,res) {
res.render('futur')
})
router.get('/evenement', function (req,res) {
res.render('futur')
})
module.exports = router;