aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.dockerignore2
-rw-r--r--Dockerfile12
-rw-r--r--README.md7
-rw-r--r--index.js17
-rw-r--r--package.json3
-rw-r--r--public/css/style.css9
-rw-r--r--views/dashboard.ejs5
-rw-r--r--views/error-login.ejs17
-rw-r--r--views/error.ejs1
-rw-r--r--views/index.ejs6
-rw-r--r--views/password.ejs3
-rw-r--r--views/register.ejs2
-rw-r--r--views/success.ejs1
13 files changed, 59 insertions, 26 deletions
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 @@
<body>
<div class="background"></div>
<div class="container">
- <img src="/img/logo.png" alt="logo" width="200">
<h1>Welcome, <%= username %>!</h1>
- <h2>bnbSO Username: <%= fso_username %></h2>
+ <h2><%= serverName %> Username: <%= fso_username %></h2>
<h2 id="simtime"></h2>
<a href="/password" class="button">Change Password</a>
- <a href="https://fso-builds.riperiperi.workers.dev" class="button">Download bnbSO Client</a>
+ <a href="https://fso-builds.riperiperi.workers.dev" class="button">Download <%= serverName %> Client</a>
<a href="/logout" class="button logout">Logout</a>
</div>
<script>
diff --git a/views/error-login.ejs b/views/error-login.ejs
new file mode 100644
index 0000000..abd3763
--- /dev/null
+++ b/views/error-login.ejs
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="/css/style.css">
+ <title>bnbAIM</title>
+</head>
+<body>
+<div class="background"></div>
+<div class="container">
+ <h1>Oh no! Something went wrong!</h1>
+ <p><%= error %></p>
+ <a href="/logout" class="button logout">Logout</a>
+</div>
+</body>
+</html>
diff --git a/views/error.ejs b/views/error.ejs
index b867d30..c128277 100644
--- a/views/error.ejs
+++ b/views/error.ejs
@@ -9,7 +9,6 @@
<body>
<div class="background"></div>
<div class="container">
- <img src="/img/logo.png" alt="logo" width="200">
<h1>Oh no! Something went wrong!</h1>
<p><%= error %></p>
</div>
diff --git a/views/index.ejs b/views/index.ejs
index 7a9b8a4..736d56d 100644
--- a/views/index.ejs
+++ b/views/index.ejs
@@ -10,9 +10,9 @@
<div class="background"></div>
<div class="container">
<img src="/img/logo.png" alt="logo" width="200">
- <p>Log into your Discord account to get access to bnbSO.</p>
- <p><i>You must be a bits & Bytes member.</i></p>
- <a class="button discord" href="/auth/discord">Login with Discord</a>
+ <p>Log into your Discord account to get access to <%= serverName %>.</p>
+ <p><i>You must be a <%= discordName %> member.</i></p>
+ <a class="button discord" href="/login">Login with Discord</a>
</div>
</body>
</html>
diff --git a/views/password.ejs b/views/password.ejs
index 8033aae..29f399a 100644
--- a/views/password.ejs
+++ b/views/password.ejs
@@ -4,12 +4,11 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/style.css">
- <title>bnbSO Login</title>
+ <title>bnbSO Change Password</title>
</head>
<body>
<div class="background"></div>
<div class="container">
- <img src="/img/logo.png" alt="logo" width="200">
<h1>Change Password</h1>
<p>If you have issues changing your password, ask the server operator to reset your password.</p>
<form method="post" action="/password/change">
diff --git a/views/register.ejs b/views/register.ejs
index d54013d..382214d 100644
--- a/views/register.ejs
+++ b/views/register.ejs
@@ -12,7 +12,6 @@
<img src="/img/logo.png" alt="logo" width="200">
<h1>Welcome to bnbSO!</h1>
<p>You will be sending the following information to register your bnbSO account</p>
- <p>Please verify that the following information is correct. You can only change your username <b>once</b>.</p>
<form method="post" action="/register">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
@@ -22,6 +21,7 @@
<input type="password" id="passwordconfirm" name="passwordconfirm">
<button type="submit">Register</button>
</form>
+<!-- <a href="#">Link your bnbSO account</a>-->
<% if (typeof error !== 'undefined') { %>
<div class="error"><%= error %></div>
<% } %>
diff --git a/views/success.ejs b/views/success.ejs
index f87ea2f..4824e19 100644
--- a/views/success.ejs
+++ b/views/success.ejs
@@ -9,7 +9,6 @@
<body>
<div class="background"></div>
<div class="container">
- <img src="/img/logo.png" alt="logo" width="200">
<h1>Success!</h1>
<p class="success"><%= success %></p>
<a href="/">Dashboard</a>