diff --git a/database.sqlite b/database.sqlite index 1b9cafb..d1ecd14 100644 Binary files a/database.sqlite and b/database.sqlite differ diff --git a/db_init.js b/db_init.js index b7d3002..163ea5c 100644 --- a/db_init.js +++ b/db_init.js @@ -22,25 +22,4 @@ function initDb(dbPath = './database.sqlite') { }); } -function initDb (dbPath = './database.sqlite') { - return new Promise((resolve, reject) => { - const db = new sqlite3.Database(dbPath, (err) => { - if (err) { - reject(err); - } else { - db.run(` - CREATE TABLE IF NOT EXISTS restaurants ( - id INTEGER PRIMARY KEY, - nom TEXT NOT NULL, - description TEXT, - adresse TEXT NOT NULL, - menu TEXT - ); - `); - } - db.close(); - resolve(); - }); - }); -}; module.exports = initDb; diff --git a/modules/auth/google.js b/modules/auth/google.js index f0bb22b..ff363dd 100644 --- a/modules/auth/google.js +++ b/modules/auth/google.js @@ -1,13 +1,14 @@ const axios = require("axios"); -const { getUserByDId } = require('../users/getUsers'); +const { getUserByGId } = require('../users/getUsers'); const { postUser } = require('../users/postUsers'); const CLIEN_ID = "71229835507-9413gbpdamv2qbcb2ov8oda2oqgcsk8q.apps.googleusercontent.com"; const GOOGLE_SECRET = "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"; -const REDIRECT_URI = "http://localhost:3000/auth/google/callback"; +const GOOGLE_REDIRECT_URI = "http://localhost:3000/auth/google/callback"; -exports.handleGoogleAuth = async (code, res) => { +exports.handleGoogleAuth = async (req, res) => { + const code = req.query.code; if (!code) return res.status(400).json({ error: "Code de validation manquant" }); try { const params = new URLSearchParams(); diff --git a/public/resto.css b/public/resto.css index d1f27df..7224c3b 100644 --- a/public/resto.css +++ b/public/resto.css @@ -49,8 +49,8 @@ main { } .chart-placeholder { - width: 150px; - height: 150px; + width: 200px; + height: 200px; background: #eee; display: flex; align-items: center; diff --git a/routes.js b/routes.js index a10b046..86b422d 100644 --- a/routes.js +++ b/routes.js @@ -22,6 +22,17 @@ router.get('/auth/discord', (req, res) => { router.get('/auth/discord/callback', require('./modules/auth/discord').handleDiscordAuth); +// Auth Google +router.get('/auth/google', (req, res) => { + const clientId = '71229835507-9413gbpdamv2qbcb2ov8oda2oqgcsk8q.apps.googleusercontent.com'; + const redirectUri = 'http://localhost:3000/auth/google/callback'; + const scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'; + const googleAuthUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${encodeURIComponent(scope)}`; + res.redirect(googleAuthUrl); +}); + +router.get('/auth/google/callback', require('./modules/auth/google').handleGoogleAuth); + // Déconnexion router.get('/logout', (req, res) => { req.session.destroy((err) => { @@ -33,22 +44,4 @@ router.get('/logout', (req, res) => { }); }); - - -// Infos resto -router.get('/restaurants/:id', async (req, res) => { - const id = req.params.id; - try { - const restaurant = await db.get(`SELECT * FROM restaurants WHERE id = ?`, [id]); - if (!restaurant) { - res.status(404).send('Restaurant non trouvé'); - } else { - res.render('restaurant', { restaurant }); - } - } catch (err) { - console.error(err); - res.status(500).send('Erreur lors de la récupération des informations du restaurant'); - } -}); - module.exports = router; \ No newline at end of file diff --git a/views/resto.ejs b/views/resto.ejs index 00a0dd1..ebd3625 100644 --- a/views/resto.ejs +++ b/views/resto.ejs @@ -21,7 +21,9 @@