diff --git a/app.js b/app.js index f2917ee..2371209 100644 --- a/app.js +++ b/app.js @@ -1,26 +1,25 @@ +const DISCORD_CLIENT_ID = "your_client_id"; +const DISCORD_CLIENT_SECRET = "your_client_secret"; +const DISCORD_CALLBACK_URL = "http://localhost:3000/auth/discord/callback"; const SESSION_SECRET = "your_session_secret"; +// ...existing code... + const express = require('express'); const session = require('express-session'); -const initDb = require('./db_init'); +const passport = require('passport'); +const DiscordStrategy = require('passport-discord').Strategy; +const SQLite = require('sqlite3').verbose(); const path = require('path'); -const expressLayouts = require('express-ejs-layouts'); - const routes = require('./routes'); const app = express(); // DB SQLite -let db; -initDb('./database.sqlite') - .then((database) => { - db = database; - console.log('Base de données initialisée.'); - }) - .catch((err) => { - console.error('Erreur lors de l\'initialisation de la base de données :', err); - process.exit(1); - }); +const db = new SQLite.Database('./database.sqlite', (err) => { + if (err) console.error('Erreur SQLite:', err); + else db.run('CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY, username TEXT, discriminator TEXT, avatar TEXT)'); +}); // Sessions app.use(session({ @@ -29,19 +28,39 @@ app.use(session({ saveUninitialized: false })); +// Passport config +passport.serializeUser((user, done) => done(null, user.id)); +passport.deserializeUser((id, done) => { + db.get('SELECT * FROM users WHERE id = ?', [id], (err, row) => { + if (err) return done(err); + done(null, row); + }); +}); + +passport.use(new DiscordStrategy({ + clientID: DISCORD_CLIENT_ID, + clientSecret: DISCORD_CLIENT_SECRET, + callbackURL: DISCORD_CALLBACK_URL, + scope: ['identify'] +}, (accessToken, refreshToken, profile, done) => { + db.run('INSERT OR REPLACE INTO users (id, username, discriminator, avatar) VALUES (?, ?, ?, ?)', + [profile.id, profile.username, profile.discriminator, profile.avatar], + (err) => { + if (err) return done(err); + done(null, profile); + } + ); +})); + +app.use(passport.initialize()); +app.use(passport.session()); + // EJS app.set('view engine', 'ejs'); app.set('views', path.join(__dirname, 'views')); -// Express EJS Layouts -app.use(expressLayouts); -app.set('layout', 'layout'); // nom du fichier layout sans .ejs - -// Static files -app.use(express.static(path.join(__dirname, 'public'))); - // Routes app.use('/', routes); -const PORT = 3000; +const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log('Serveur lancé sur http://localhost:' + PORT)); diff --git a/database.sqlite b/database.sqlite index d1ecd14..b1452ce 100644 Binary files a/database.sqlite and b/database.sqlite differ diff --git a/db_init.js b/db_init.js deleted file mode 100644 index 163ea5c..0000000 --- a/db_init.js +++ /dev/null @@ -1,25 +0,0 @@ -const SQLite = require('sqlite3').verbose(); - -function initDb(dbPath = './database.sqlite') { - return new Promise((resolve, reject) => { - const db = new SQLite.Database(dbPath, (err) => { - if (err) { - reject(err); - } else { - db.run(`CREATE TABLE IF NOT EXISTS users ( - id TEXT PRIMARY KEY, - username TEXT, - discord_id TEXT DEFAULT NULL, - google_id TEXT DEFAULT NULL, - discriminator TEXT, - avatar TEXT - )`, (err) => { - if (err) reject(err); - else resolve(db); - }); - } - }); - }); -} - -module.exports = initDb; diff --git a/db_instance.js b/db_instance.js deleted file mode 100644 index 78969cb..0000000 --- a/db_instance.js +++ /dev/null @@ -1,4 +0,0 @@ -// Singleton pour partager l'instance db partout -const SQLite = require('sqlite3').verbose(); -const db = new SQLite.Database('./database.sqlite'); -module.exports = db; diff --git a/modules/auth/discord.js b/modules/auth/discord.js deleted file mode 100644 index 21569dc..0000000 --- a/modules/auth/discord.js +++ /dev/null @@ -1,58 +0,0 @@ -const axios = require("axios"); - -const { getUserByDId } = require('./../users/getUsers'); -const { postUser } = require('./../users/postUsers'); - -const BOT_ID = "1410258710407811082"; -const BOT_SECRET = "Bn5FGfrNZCdG1XpCciOcLkzLmrz6fhib"; -const REDIRECT_URI = "http://localhost:3000/auth/discord/callback"; - -exports.handleDiscordAuth = 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(); - params.append("client_id", BOT_ID); - params.append("client_secret", BOT_SECRET); - params.append("grant_type", "authorization_code"); - params.append("code", code); - params.append("redirect_uri", REDIRECT_URI); - params.append("scope", "identify email"); - const tokenData = await axios.post( - "https://discord.com/api/oauth2/token", - params, - { - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - } - ); - const accessToken = tokenData.data.access_token; - const userResponse = await axios.get("https://discord.com/api/users/@me", { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - const userData = userResponse.data; - if (!userData || !userData.id) { - console.error('Réponse Discord inattendue:', userResponse.data); - return res.status(500).json({ error: "Impossible de récupérer les infos utilisateur depuis Discord", details: userResponse.data }); - } - let savedUser = await getUserByDId(userData.id); - if (!savedUser) { - const newUser = { - username: userData.username, - discord_id: userData.id, - avatar: userData.avatar - ? `https://cdn.discordapp.com/avatars/${userData.id}/${userData.avatar}.png` - : null, - }; - savedUser = await postUser(newUser); - } - req.session.user = savedUser; - res.redirect('/'); - } catch (err) { - console.error(err.response?.data || err.message); - res.status(500).json({ error: "Erreur lors de la connexion à Discord" }); - } -}; \ No newline at end of file diff --git a/modules/auth/google.js b/modules/auth/google.js deleted file mode 100644 index 1058416..0000000 --- a/modules/auth/google.js +++ /dev/null @@ -1,54 +0,0 @@ -const axios = require("axios"); - -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 GOOGLE_REDIRECT_URI = "http://localhost:3000/auth/google/callback"; - -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(); - params.append("client_id", CLIEN_ID); - params.append("client_secret", GOOGLE_SECRET); - params.append("grant_type", "authorization_code"); - params.append("code", code); - params.append("redirect_uri", GOOGLE_REDIRECT_URI); - const tokenData = await axios.post( - "https://oauth2.googleapis.com/token", - params, - { - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - } - ); - const accessToken = tokenData.data.access_token; - const userResponse = await axios.get("https://www.googleapis.com/oauth2/v2/userinfo", { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - const userData = userResponse.data; - if (!userData || !userData.id) { - console.error("Réponse Google inattendue:", userResponse.data); - return res.status(500).json({ error: "Impossible de récupérer les infos utilisateur depuis Google", details: userResponse.data }); - } - let savedUser = await getUserByGId(userData.id); - if (!savedUser) { - const newUser = { - username: userData.name || userData.email, - google_id: userData.id, - }; - savedUser = await postUser(newUser); - } - req.session.user = savedUser; - res.redirect('/'); - } catch (err) { - console.error(err.response?.data || err.message); - res.status(500).json({ error: "Erreur lors de la connexion à Google" }); - } -}; \ No newline at end of file diff --git a/modules/users/getUsers.js b/modules/users/getUsers.js deleted file mode 100644 index 0a197e2..0000000 --- a/modules/users/getUsers.js +++ /dev/null @@ -1,26 +0,0 @@ - -const db = require('../../db_instance'); - -module.exports.getUserByDId = async (discordId) => { - return new Promise((resolve, reject) => { - const query = `SELECT * FROM users WHERE discord_id = ?`; - db.get(query, [discordId], (err, row) => { - if (err) { - return reject(err); - } - resolve(row); - }); - }); -} - -module.exports.getUserByGId = async (discordId) => { - return new Promise((resolve, reject) => { - const query = `SELECT * FROM users WHERE google_id = ?`; - db.get(query, [discordId], (err, row) => { - if (err) { - return reject(err); - } - resolve(row); - }); - }); -} \ No newline at end of file diff --git a/modules/users/postUsers.js b/modules/users/postUsers.js deleted file mode 100644 index 3055ee1..0000000 --- a/modules/users/postUsers.js +++ /dev/null @@ -1,20 +0,0 @@ -const db = require('../../db_instance'); - -module.exports.postUser = (user) => { - return new Promise((resolve, reject) => { - const query = `INSERT INTO users (id, username, discord_id, discriminator, avatar) VALUES (?, ?, ?, ?, ?)`; - const params = [ - user.id, - user.username, - user.discord_id, - user.discriminator, - user.avatar - ]; - db.run(query, params, function(err) { - if (err) { - return reject(err); - } - resolve({ id: this.lastID, ...user }); - }); - }); -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 873dfae..28f1223 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,12 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "axios": "^1.11.0", + "dotenv": "^17.2.1", "ejs": "^3.1.10", "express": "^5.1.0", - "express-ejs-layouts": "^2.5.1", "express-session": "^1.18.2", + "passport": "^0.7.0", + "passport-discord": "^0.1.4", "sqlite3": "^5.1.7" } }, @@ -158,23 +159,6 @@ "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", "license": "MIT" }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, - "node_modules/axios": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.11.0.tgz", - "integrity": "sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.4", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -201,6 +185,15 @@ ], "license": "MIT" }, + "node_modules/base64url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", + "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/bindings": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", @@ -371,18 +364,6 @@ "color-support": "bin.js" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -477,15 +458,6 @@ "node": ">=4.0.0" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -511,6 +483,18 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "17.2.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz", + "integrity": "sha512-kQhDYKZecqnM0fCnzI5eIv5L4cAe/iRI+HqMbO/hbRdTAeXDG+M9FjipUxNfbARuEg4iHIbhnhs78BCHNbSxEQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -628,21 +612,6 @@ "node": ">= 0.4" } }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -709,11 +678,6 @@ "url": "https://opencollective.com/express" } }, - "node_modules/express-ejs-layouts": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/express-ejs-layouts/-/express-ejs-layouts-2.5.1.tgz", - "integrity": "sha512-IXROv9n3xKga7FowT06n1Qn927JR8ZWDn5Dc9CJQoiiaaDqbhW5PDmWShzbpAa2wjWT1vJqaIM1S6vJwwX11gA==" - }, "node_modules/express-session": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.2.tgz", @@ -786,63 +750,6 @@ "node": ">= 0.8" } }, - "node_modules/follow-redirects": { - "version": "1.15.11", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", - "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz", - "integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.2", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/form-data/node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/form-data/node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -1036,21 +943,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", @@ -1635,6 +1527,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/oauth": { + "version": "0.10.2", + "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.10.2.tgz", + "integrity": "sha512-JtFnB+8nxDEXgNyniwz573xxbKSOu3R8D40xQKqcjwJ2CDkYqUDI53o6IuzDJBx60Z8VKCm271+t8iFjakrl8Q==", + "license": "MIT" + }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", @@ -1702,6 +1600,61 @@ "node": ">= 0.8" } }, + "node_modules/passport": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", + "license": "MIT", + "dependencies": { + "passport-strategy": "1.x.x", + "pause": "0.0.1", + "utils-merge": "^1.0.1" + }, + "engines": { + "node": ">= 0.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jaredhanson" + } + }, + "node_modules/passport-discord": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/passport-discord/-/passport-discord-0.1.4.tgz", + "integrity": "sha512-VJWPYqSOmh7SaCLw/C+k1ZqCzJnn2frrmQRx1YrcPJ3MQ+Oa31XclbbmqFICSvl8xv3Fqd6YWQ4H4p1MpIN9rA==", + "license": "ISC", + "dependencies": { + "passport-oauth2": "^1.5.0" + } + }, + "node_modules/passport-oauth2": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.8.0.tgz", + "integrity": "sha512-cjsQbOrXIDE4P8nNb3FQRCCmJJ/utnFKEz2NX209f7KOHPoX18gF7gBzBbLLsj2/je4KrgiwLLGjf0lm9rtTBA==", + "license": "MIT", + "dependencies": { + "base64url": "3.x.x", + "oauth": "0.10.x", + "passport-strategy": "1.x.x", + "uid2": "0.0.x", + "utils-merge": "1.x.x" + }, + "engines": { + "node": ">= 0.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jaredhanson" + } + }, + "node_modules/passport-strategy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", + "integrity": "sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA==", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -1721,6 +1674,11 @@ "node": ">=16" } }, + "node_modules/pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -1787,12 +1745,6 @@ "node": ">= 0.10" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT" - }, "node_modules/pump": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz", @@ -2375,6 +2327,12 @@ "node": ">= 0.8" } }, + "node_modules/uid2": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz", + "integrity": "sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==", + "license": "MIT" + }, "node_modules/unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", @@ -2410,6 +2368,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 7e42484..7b151f3 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,12 @@ "license": "ISC", "type": "commonjs", "dependencies": { - "axios": "^1.11.0", + "dotenv": "^17.2.1", "ejs": "^3.1.10", "express": "^5.1.0", - "express-ejs-layouts": "^2.5.1", "express-session": "^1.18.2", + "passport": "^0.7.0", + "passport-discord": "^0.1.4", "sqlite3": "^5.1.7" } } diff --git a/public/logo.png b/public/logo.png deleted file mode 100644 index a6050cd..0000000 Binary files a/public/logo.png and /dev/null differ diff --git a/public/resto.css b/public/resto.css deleted file mode 100644 index 7224c3b..0000000 --- a/public/resto.css +++ /dev/null @@ -1,111 +0,0 @@ -main { - text-align: left !important; -} - -.restaurant-page { - width: 90%; - max-width: 1200px; - margin: auto; -} - -.header { - display: flex; - justify-content: space-between; - align-items: flex-start; - margin-top: 20px; -} - -.restaurant-info h1 { - margin: 0; - font-size: 24px; -} - -.heart { - display: inline-flex; - align-items: center; - justify-content: center; - background: #ececec; - border-radius: 50%; - width: 32px; - height: 32px; - font-size: 20px; - margin-left: 8px; - box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04); -} - -.rating { - display: flex; - align-items: center; - margin: 10px 0; - gap: 10px; -} - -.btn { - background: #999; - border: none; - color: white; - padding: 5px 10px; - cursor: pointer; -} - -.chart-placeholder { - width: 200px; - height: 200px; - background: #eee; - display: flex; - align-items: center; - justify-content: center; - font-size: 12px; -} - -.main-image { - width: 100%; - height: 200px; - background: #ccc; - margin: 20px 0; -} - -.description { - background: #f9f9f9; - padding: 15px; - margin-bottom: 20px; -} - -.gallery { - display: flex; - justify-content: space-between; - margin-bottom: 30px; -} - -.gallery-item { - width: 32%; - height: 150px; - background: #ddd; -} - -.reviews-title { - background: #eee; - padding: 10px; - margin: 0; -} - -.reviews { - display: flex; - flex-direction: column; - gap: 20px; - margin: 20px 0; -} - -.review { - background: #f5f5f5; - padding: 15px; - border: 1px solid #ddd; -} - -.review h3 { - margin-top: 0; -} - -.review-rating div { - margin-top: 5px; -} diff --git a/public/style.css b/public/style.css deleted file mode 100644 index e3ce7a2..0000000 --- a/public/style.css +++ /dev/null @@ -1,294 +0,0 @@ -body { - margin: 0; - font-family: Arial, sans-serif; - background: linear-gradient(135deg, #f8f6fc 0%, #fffbe7 100%); - color: #7a5c1e; -} - -header { - background: linear-gradient(90deg, #8e68aa 60%, #cb8d37 100%); - color: white; - display: flex; - align-items: center; - justify-content: space-between; - padding: 10px 20px; - box-shadow: 0 2px 8px rgba(140, 104, 170, 0.08); -} - -header h1 { - font-size: 1.2rem; -} - -.search-bar { - flex-grow: 1; - margin: 0 20px; -} - -.search-bar input { - width: 100%; - padding: 5px; - border: none; - border-radius: 4px; -} - -.account { - background: linear-gradient(90deg, #cb8d37 60%, #8e68aa 100%); - padding: 6px 12px; - border-radius: 4px; - color: white; - cursor: pointer; - font-weight: bold; - transition: background 0.2s; -} - -.account:hover { - background: #a97b2c; -} - -main { - padding: 20px; - text-align: center; -} - -main h2 { - font-size: 2rem; - margin: 10px 0; -} - -.sections { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 30px; - margin-top: 20px; -} - -.section h3 { - margin-bottom: 15px; - text-align: left; -} - -.cards { - display: flex; - flex-direction: column; - gap: 15px; -} - -.card { - background: #ddd; - border-radius: 8px; - padding: 15px; - display: flex; - justify-content: space-between; - align-items: center; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); -} - -.card-info { - text-align: left; -} - -.card-info h4 { - margin: 0 0 5px; - font-weight: bold; -} - -.card-photo { - background: #8e68aa; - width: 120px; - height: 80px; - display: flex; - align-items: center; - justify-content: center; - font-size: 0.9rem; - color: #555; -} - -footer { - background: #8e68aa; - text-align: center; - padding: 10px; - margin-top: 30px; -} - -footer a { - margin: 0 10px; - text-decoration: none; - color: #333; -} - -/* Header layout amélioré */ -.main-header { - background: linear-gradient(90deg, #8e68aa 60%, #cb8d37 100%); - color: white; - box-shadow: 0 2px 8px rgba(140, 104, 170, 0.08); - padding: 0; -} - -.header-content { - display: flex; - align-items: center; - justify-content: space-between; - padding: 10px 20px; - max-width: 1200px; - margin: 0 auto; - width: 100%; - gap: 0; -} - -.header-left { - display: flex; - align-items: center; - min-width: 220px; -} - -.header-left h1 { - font-size: 1.4rem; - margin: 0 0 0 10px; - white-space: nowrap; -} - -.header-center { - flex: 1 1 0; - display: flex; - justify-content: center; -} - -.header-right { - display: flex; - align-items: center; - min-width: 260px; - justify-content: flex-end; -} - -.search-bar { - flex: 1 1 300px; - max-width: 700px; - margin: 0 18px; -} - -.search-bar input { - width: 100%; - padding: 7px 12px; - border: none; - border-radius: 4px; - font-size: 1rem; -} - -.account { - display: flex; - align-items: center; - background: linear-gradient(90deg, #cb8d37 60%, #8e68aa 100%); - padding: 6px 12px; - border-radius: 4px; - color: white; - font-weight: bold; - transition: background 0.2s; -} - -.account a { - color: white; - text-decoration: none; - margin-left: 8px; - font-weight: bold; -} - -.account a:first-child { - margin-left: 0; -} - -.account:hover { - background: #a97b2c; -} - -.social-buttons { - display: flex; - gap: 12px; - margin: 0; -} - -.btn-social { - display: flex; - align-items: center; - gap: 8px; - padding: 8px 18px; - border: none; - border-radius: 30px; - font-size: 1rem; - font-weight: 600; - cursor: pointer; - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07); - transition: transform 0.1s, box-shadow 0.2s; - outline: none; - text-decoration: none; -} - -.btn-social:active { - transform: scale(0.97); - box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); -} - -.btn-google { - background: #fff; - color: #444; - border: 1px solid #e0e0e0; -} -.btn-google:hover { - background: #f5f5f5; -} - -.btn-discord { - background: #5865f2; - color: #fff; - border: none; -} -.btn-discord:hover { - background: #4752c4; -} - -.icon-social { - width: 22px; - height: 22px; - display: inline-block; - vertical-align: middle; -} - -.logo { - height: 40px; - width: 40px; - border-radius: 8px; - margin-right: 10px; - object-fit: contain; -} - -/* Responsive */ -@media (max-width: 900px) { - .header-content { - flex-direction: column; - align-items: stretch; - gap: 10px; - } - .header-center { - justify-content: stretch; - margin: 10px 0; - } - .header-right { - justify-content: center; - min-width: 0; - margin-top: 10px; - } - .search-bar { - min-width: 180px; - max-width: 100%; - margin: 10px 0; - } - .account { - margin-top: 10px; - } - .sections { - grid-template-columns: 1fr; - } - .social-buttons { - flex-direction: column; - gap: 12px; - } -} diff --git a/routes.js b/routes.js index 86b422d..73b52f7 100644 --- a/routes.js +++ b/routes.js @@ -1,47 +1,27 @@ const express = require('express'); +const passport = require('passport'); const router = express.Router(); // Page d'accueil router.get('/', (req, res) => { - res.render('index', { user: req.session.user }); -}); - -// Page resto -router.get('/resto/:id', (req, res) => { - res.render('resto', { user: req.session.user }); + res.render('index', { user: req.user }); }); // Auth Discord -router.get('/auth/discord', (req, res) => { - const clientId = '1410258710407811082'; - const redirectUri = 'http://localhost:3000/auth/discord/callback'; - const scope = 'identify email'; - const discordAuthUrl = `https://discord.com/api/oauth2/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scope}`; - res.redirect(discordAuthUrl); -}); +router.get('/auth/discord', passport.authenticate('discord')); -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); +router.get('/auth/discord/callback', + passport.authenticate('discord', { failureRedirect: '/' }), + (req, res) => { + res.redirect('/'); + } +); // Déconnexion router.get('/logout', (req, res) => { - req.session.destroy((err) => { - if (err) { - console.error(err); - return res.send("Erreur lors de la déconnexion"); - } - res.redirect("/"); // Redirige vers la page d'accueil + req.logout(() => { + res.redirect('/'); }); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/views/index.ejs b/views/index.ejs index 92506de..12071c3 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,78 +1,76 @@ -
-

L’EPICURIEN

- Logo de l'entreprise -
-
- -
-

Restaurants les plus proches

- + + + + + Diagramme Radar avec Chart.js + + + +
+
- - \ No newline at end of file + + + \ No newline at end of file diff --git a/views/layout.ejs b/views/layout.ejs deleted file mode 100644 index 2fdfeb9..0000000 --- a/views/layout.ejs +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - L'EPICURIEN - - - - - -
-
- -
- -
-
- -
-
-
- -
- <%- body %> -
- - - - - \ No newline at end of file diff --git a/views/resto.ejs b/views/resto.ejs deleted file mode 100644 index ebd3625..0000000 --- a/views/resto.ejs +++ /dev/null @@ -1,166 +0,0 @@ - - -
- -
-
-

- Nom restaurant - - <% if (user) { %> - ❤️ - <% } else { %> - 🤍 - <% } %> - -

-

Adresse

-
- ⭐️⭐️⭐️⭐️⭐️ - Voir tous les avis -
-
-
-
- -
-
-
- - -
- - -
-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod - tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim - veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea - commodo consequat. Duis aute irure dolor in reprehenderit in voluptate - velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint - occaecat cupidatat -

-
- - - - - -

Avis

-
-
-

Titre avis

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. -

-
-
Qualité des plats ⭐⭐⭐⭐⭐
-
Service ⭐⭐⭐⭐⭐
-
Ambiance ⭐⭐⭐⭐⭐
-
Accessibilité ⭐⭐⭐⭐⭐
-
Tarif ⭐⭐⭐⭐⭐
-
-
- -
-

Titre avis

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. -

-
-
Qualité des plats ⭐⭐⭐⭐⭐
-
Service ⭐⭐⭐⭐⭐
-
Ambiance ⭐⭐⭐⭐⭐
-
Accessibilité ⭐⭐⭐⭐⭐
-
Tarif ⭐⭐⭐⭐⭐
-
-
- -
-

Titre avis

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. -

-
-
Qualité des plats ⭐⭐⭐⭐⭐
-
Service ⭐⭐⭐⭐⭐
-
Ambiance ⭐⭐⭐⭐⭐
-
Accessibilité ⭐⭐⭐⭐⭐
-
Tarif ⭐⭐⭐⭐⭐
-
-
-
- - - - \ No newline at end of file