add little css & add session

This commit is contained in:
Arthur Puechberty
2026-01-15 21:57:42 +01:00
parent 87e339c75b
commit f8eae61818
5 changed files with 154 additions and 1 deletions
+12
View File
@@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"connect-sqlite3": "^0.9.16",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"discord.js": "^14.25.1", "discord.js": "^14.25.1",
"dotenv": "^17.2.3", "dotenv": "^17.2.3",
@@ -553,6 +554,17 @@
"license": "MIT", "license": "MIT",
"optional": true "optional": true
}, },
"node_modules/connect-sqlite3": {
"version": "0.9.16",
"resolved": "https://registry.npmjs.org/connect-sqlite3/-/connect-sqlite3-0.9.16.tgz",
"integrity": "sha512-2gqo0QmcBBL8p8+eqpBETn7RgM/PaoKvpQGl8PfjEgwlr0VuMYNMxRJRrRCo3KR3fxMYeSsCw2tGNG0JKN9Nvg==",
"dependencies": {
"sqlite3": "^5.0.2"
},
"engines": {
"node": ">=0.4.x"
}
},
"node_modules/console-control-strings": { "node_modules/console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
+1
View File
@@ -23,6 +23,7 @@
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"dependencies": { "dependencies": {
"connect-sqlite3": "^0.9.16",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"discord.js": "^14.25.1", "discord.js": "^14.25.1",
"dotenv": "^17.2.3", "dotenv": "^17.2.3",
+103
View File
@@ -0,0 +1,103 @@
:root {
--bg: #0f1115;
--bg-card: #161a22;
--text: #e6e6eb;
--muted: #9aa0b4;
--primary: #5865F2; /* couleur Discord */
--primary-hover: #4752c4;
--border: #23283a;
}
* {
box-sizing: border-box;
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
body {
margin: 0;
background-color: var(--bg);
color: var(--text);
min-height: 100vh;
}
/* NAVBAR */
nav {
display: flex;
gap: 20px;
padding: 16px 24px;
background: var(--bg-card);
border-bottom: 1px solid var(--border);
}
nav a {
color: var(--muted);
text-decoration: none;
font-weight: 500;
}
nav a:hover {
color: var(--text);
}
#profile {
margin-left: auto;
display: flex;
align-items: center;
gap: 10px;
}
#avatar {
width: 32px;
height: 32px;
border-radius: 50%;
}
#username {
color: var(--text);
font-weight: 500;
}
#logout {
color: var(--muted);
text-decoration: none;
}
#logout:hover {
color: var(--text);
}
/* CONTENU */
h1 {
margin: 40px 0 10px;
text-align: center;
font-size: 3rem;
}
h2 {
margin-top: 40px;
text-align: center;
}
p {
text-align: center;
color: var(--muted);
}
/* BOUTON INVITE */
#invite-link {
display: block;
width: fit-content;
margin: 30px auto;
padding: 14px 26px;
background: var(--primary);
color: white;
text-decoration: none;
border-radius: 10px;
font-weight: 600;
transition: background 0.2s ease, transform 0.1s ease;
}
#invite-link:hover {
background: var(--primary-hover);
transform: translateY(-1px);
}
+27
View File
@@ -2,14 +2,25 @@
<html> <html>
<head> <head>
<title>LazyBot - Bot Discord</title> <title>LazyBot - Bot Discord</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
</head> </head>
<body> <body>
<nav> <nav>
<a href="/">Accueil</a> <a href="/">Accueil</a>
<a href="/dashboard">Tableau de bord</a> <a href="/dashboard">Tableau de bord</a>
<div id="profil">
<img id="avatar" src="" alt="Avatar">
<span id="username"></span>
<a id="logout" href="/logout">Se déconnecter</a>
</div>
</nav> </nav>
<h1>LazyBot</h1> <h1>LazyBot</h1>
<a id="invite-link" href="#">Ajouter à Discord</a> <a id="invite-link" href="#">Ajouter à Discord</a>
<h2>Ajout du bot</h2>
<p>Message de bienvenue et d'au revoir personnalisables.</p>
</body> </body>
<script> <script>
fetch("/invite-bot") fetch("/invite-bot")
@@ -21,5 +32,21 @@
.catch(() => { .catch(() => {
console.log("Impossible de récupérer le lien du bot."); console.log("Impossible de récupérer le lien du bot.");
}); });
fetch("/api/user")
.then(res => {
if (!res.ok) throw new Error("Utilisateur non connecté"); // gère les erreurs HTTP
return res.json();
})
.then(user => {
document.getElementById("username").textContent = `${user.username}`;
document.getElementById("avatar").src = `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`;
})
.catch(() => {
const profilDiv = document.getElementById("profil");
profilDiv.style.display = "none";
});
</script> </script>
</html> </html>
+11 -1
View File
@@ -2,6 +2,7 @@ require("dotenv").config(); // charge les variables depuis .env
const express = require("express"); const express = require("express");
const session = require("express-session"); const session = require("express-session");
const SQLiteStore = require("connect-sqlite3")(session);
const fetch = require("cross-fetch"); // fetch compatible Node const fetch = require("cross-fetch"); // fetch compatible Node
const path = require("path"); const path = require("path");
@@ -20,9 +21,11 @@ const REDIRECT_URI = process.env.REDIRECT_URI;
// --- Session setup --- // --- Session setup ---
app.use(session({ app.use(session({
store: new SQLiteStore({ db: "sessions.sqlite", dir: "./" }),
secret: process.env.SESSION_SECRET, secret: process.env.SESSION_SECRET,
resave: false, resave: false,
saveUninitialized: true, saveUninitialized: false,
cookie: { maxAge: 7*24*60*60*1000 } // 7 jours
})); }));
// --- Servir le dossier public --- // --- Servir le dossier public ---
@@ -82,6 +85,13 @@ app.get("/auth/discord/callback", async (req, res) => {
} }
}); });
app.get("/logout", (req, res) => {
req.session.destroy();
res.redirect("/");
});
// --- API pour récupérer l'objet user côté front --- // --- API pour récupérer l'objet user côté front ---
app.get("/api/user", (req, res) => { app.get("/api/user", (req, res) => {
if (req.session.user) { if (req.session.user) {