From 60550de93e761d5ea4956f504d0b18680ce137cd Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 4 May 2025 10:48:45 -0400 Subject: Docker support; Logout button --- .dockerignore | 2 ++ Dockerfile | 12 ++++++++++++ README.md | 7 +++++-- index.js | 17 +++++++---------- package.json | 3 --- public/css/style.css | 9 +++++++++ views/dashboard.ejs | 5 ++--- views/error-login.ejs | 17 +++++++++++++++++ views/error.ejs | 1 - views/index.ejs | 6 +++--- views/password.ejs | 3 +-- views/register.ejs | 2 +- views/success.ejs | 1 - 13 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 views/error-login.ejs diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..37d7e73 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..075d8ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM oven/bun:latest + +WORKDIR /app + +COPY bun.lockb . +COPY package.json . + +RUN bun install + +COPY . . + +ENTRYPOINT ["bun", "start"] diff --git a/README.md b/README.md index bb32808..865e3d2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# bnbso-auth -Web authentication for bnbSO (registering accounts, changing passwords) using Discord authentication. Designed for FreeSO-based servers. +# freeso-discord-auth +Web authentication for FreeSO (registering accounts, changing passwords) using Discord authentication. To install dependencies: @@ -13,4 +13,7 @@ To run: bun run index.js ``` +# How this works? +The website requires to log into Discord, and it checks if the user is on a specific server (as defined on the .env file). Then it checks if the user is registered on a local database, if not then it prompts the user to register a FreeSO account. After, once the user registers the account, it makes a POST request to `/userapi/registration`. Otherwise, if the user is registered, then it redirects the user to the dashboard which has options to change the password and download the client. + This project was created using `bun init` in bun v1.1.38. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/index.js b/index.js index d1744d4..33bc597 100644 --- a/index.js +++ b/index.js @@ -80,16 +80,15 @@ app.get("/", async (req, res) => { } if (row) { - return res.render('dashboard', { ...req.user, fso_username: row.fso_username }); + return res.render('dashboard', { ...req.user, fso_username: row.fso_username, serverName: process.env.SERVER_NAME || 'FreeSO' }); } else { return res.render('register', req.user); } }); } else { - return res.render('error', { error: 'You must be a member of that server to access this page.' }); - } + return res.render('error-login', { error: 'You must be a member of that server to access this page.' }); } } else { - res.render('index'); + res.render('index', { serverName: process.env.SERVER_NAME || 'FreeSO', discordName: process.env.DISCORD_NAME || 'Discord' }); } }); @@ -139,7 +138,7 @@ app.get('/password', (req, res) => { if (req.isAuthenticated()) { res.render('password'); } else { - res.redirect("/auth/discord"); + res.redirect("/login"); } }); @@ -174,24 +173,22 @@ app.post('/password/change', upload.none(), async (req, res) => { const errorMessage = statusMessages.password_reset_errors[errorKey] || "Something went wrong"; return res.render('password', { ...req.user, error: errorMessage }); + } else { + return res.render('success', { ...req.user, success: "Password changed successfully!" }); } - - return res.render('success', { ...req.user, success: "Password changed successfully!" }); } }); - } catch (error) { console.error("Error during password change:", error); return res.render('password', { ...req.user, error: "An error occurred during password change, contact server operator." }); } - } else { res.status(401).send("Unauthorized."); } }); app.get( - "/auth/discord", + "/login", passport.authenticate("discord", { scope: ["identify", "guilds"] }) ); diff --git a/package.json b/package.json index ed9fd67..3e534bc 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,6 @@ "devDependencies": { "@types/bun": "latest" }, - "peerDependencies": { - "typescript": "^5.0.0" - }, "dependencies": { "axios": "^1.7.9", "dotenv": "^16.4.7", diff --git a/public/css/style.css b/public/css/style.css index 1472a8c..fcf210f 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -127,6 +127,7 @@ input[type=password] { button { background-color: #00633a; + font-size: 1em; color: white; padding: 14px 20px; margin: 8px 0; @@ -136,6 +137,14 @@ button { transition: 0.2s; } +button:hover { + background-color: #008c4a; +} + +button:active { + background-color: #008c4a; +} + .error { color: #f88c8c; font-size: 1.5em; diff --git a/views/dashboard.ejs b/views/dashboard.ejs index b7c82d5..e63c458 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -9,12 +9,11 @@
- logo

Welcome, <%= username %>!

-

bnbSO Username: <%= fso_username %>

+

<%= serverName %> Username: <%= fso_username %>

Change Password - Download bnbSO Client + Download <%= serverName %> Client Logout