Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Discord-based registration with Minecraft backed auth and user profiles. #99

Merged
merged 86 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
449acec
Delete message after filtering prohibited content.
benrobson Nov 14, 2023
3f3ab87
Fix spacing in network log messages.
benrobson Nov 14, 2023
08276c8
Make usernames more presentable in logs.
benrobson Nov 14, 2023
6dffe68
Remove deleted channel field from being mentioned twice.
benrobson Nov 14, 2023
e6e86b3
Fixed issue where filter errors after response is sent.
benrobson Nov 14, 2023
9461d6d
Changed from HEX to Colour
benrobson Nov 14, 2023
bb011d4
Add /poll command.
benrobson Nov 14, 2023
8c8c14d
Add page descriptions to headers.
benrobson Nov 14, 2023
582aa41
Added keywords and SEO option to configuration.
benrobson Nov 14, 2023
7d3f93d
Add documentation badges for list and editors.
benrobson Nov 15, 2023
af0bce5
Push mobile view changes for session views.
benrobson Nov 15, 2023
e55c5d9
Resolved mobile styling issues with dashboard views.
benrobson Nov 15, 2023
7b4b73e
Added a staffChannel config option and a /staffhelp command
benrobson Nov 15, 2023
ed2c96e
Resolve issues with cookie banner not showing on /register
benrobson Nov 15, 2023
75e2f8d
Made urgent change to hasPermission, allowing non-logged in users to …
benrobson Nov 16, 2023
89f7834
Reformat all project files using Prettier. (#90)
benrobson Nov 20, 2023
726cf14
Resolve issue with logout crashing.
benrobson Nov 20, 2023
2bd95cb
Separate redirect route into own file, add config option for kb and a…
benrobson Nov 24, 2023
781f49d
Change node engine to support node 18. (#92)
benrobson Nov 24, 2023
57da364
Implementation of a Ranks/donation page. (#91)
benrobson Nov 24, 2023
b3d55c3
Change rank page descriptor.
benrobson Nov 24, 2023
f94d9ce
Commit start of rego process.
benrobson Nov 27, 2023
2ba887f
Add more routes
benrobson Nov 27, 2023
356bcfc
Implement 2fa interactive form element.
benrobson Nov 27, 2023
7e884ae
Install packages for email integration
benrobson Nov 27, 2023
5588750
Implement email template draft and smtp credentials.
benrobson Dec 2, 2023
fcb24bd
Commence more work on controller and tests for emails.
benrobson Dec 2, 2023
25a6cbb
Working on pathing.
benrobson Dec 2, 2023
680f733
Fix pathing on email template.
benrobson Dec 6, 2023
1b93e0f
Add email header and footer and fix up routes.
benrobson Jan 23, 2024
96da6ce
Add a rough template draft of registration
benrobson Jan 23, 2024
dddc92c
Change registration gateway to discord, commence working on Minecraft…
benrobson Jan 27, 2024
9bbbef0
Add user verification via /verify
benrobson Jan 28, 2024
fc64eba
Remove all old rego code and mentions to passwords, remove email view…
benrobson Jan 28, 2024
01e16fc
Add token code expiry and draft a expiry cron task.
benrobson Jan 28, 2024
181b91a
Refactor getUser() into UserGetter
benrobson Feb 5, 2024
660a053
Push user verification service.
benrobson Feb 17, 2024
46945a7
Commence drafting profiles and finalising login gateway
benrobson Feb 20, 2024
77cd86d
Add coming soon alerts on profile features.
benrobson Feb 20, 2024
3dad546
Commit more profile work and db profile changes.
benrobson Feb 20, 2024
d5fb75f
Applied permissions to profile.
benrobson Feb 21, 2024
6b30675
Add example.env and config files.
benrobson Feb 21, 2024
9518e69
Added Minecraft login and chat audits, also added website login.
benrobson Feb 21, 2024
504c490
Added discord voice and message audit events.
benrobson Feb 21, 2024
c6058f7
Filled in fields for audit to complete feature development.
benrobson Feb 21, 2024
28e3a02
Start work on profile editor.
benrobson Feb 22, 2024
c68a7cd
Start implementing social connections into editor.
benrobson Feb 22, 2024
bff9488
Finalise design for profile editor.
benrobson Feb 22, 2024
f6dd446
Implemented all of the base work for API routes and controllers.
benrobson Feb 22, 2024
11a0692
Start on profile/display in editor and fix issue with Gravatar.
benrobson Feb 24, 2024
a58e425
Finalise Social Connections in display and editor.
benrobson Feb 24, 2024
3c8fb7c
Fix permission node of everyone able to see dashboard, and open new t…
benrobson Feb 24, 2024
b99762b
Audit: If no data, then display no data instead of invalid date
benrobson Feb 24, 2024
fb6ed81
Added profile stats for total logins and playtime.
benrobson Feb 25, 2024
fa35113
Add latest session with online and offline indicators.
benrobson Feb 26, 2024
48ff0d5
Add support for verification server in /server
benrobson Mar 14, 2024
7aa3a9a
Resolved issues with Server types displaying all instead of their type.
benrobson Mar 16, 2024
dcd00d1
Create dbupgrade.sql
birdwing Apr 16, 2024
3ab313f
Commence port to new schema.
benrobson Apr 16, 2024
c2c89f1
Fix result type return in user api and added 17 global images.
benrobson Apr 18, 2024
5454ae8
Make unregistered failure link back to rego page.
benrobson Apr 19, 2024
5d25544
Set audit to skip for discord voice and chat if discord is not linked.
benrobson Apr 19, 2024
d70b343
Resolved issues with user api creation.
benrobson Apr 25, 2024
b0b12ec
Merge branch 'master' of https://github.com/ModularSoftAU/zander-web …
benrobson Apr 25, 2024
abdf563
Resolve issues with messages attempting to send to channels.
benrobson Apr 25, 2024
8d5f6ae
Require the webhook package.
benrobson Apr 25, 2024
22265ef
Rollback to d70b3432988e63ddf9522ff5db2c09afd0710a92
Apr 26, 2024
7166296
Merge branch 'feat-rego' of https://github.com/ModularSoftAU/zander-w…
Apr 26, 2024
3a8a122
Merge branch 'master' of https://github.com/ModularSoftAU/zander-web …
benrobson Apr 26, 2024
4de3711
Merge branch 'feat-rego' of https://github.com/ModularSoftAU/zander-w…
benrobson Apr 26, 2024
f94b0c8
Changes to user route and troubleshooting discord login.
benrobson Apr 27, 2024
8e86712
Remove redirect returns.
benrobson Apr 27, 2024
0fcf7fd
Add troubleshooting to callback.
benrobson Apr 27, 2024
7f7f215
Push further troubleshooting.
benrobson Apr 27, 2024
46f5071
Add troubleshooting to isRegistered
benrobson Apr 27, 2024
cc188cb
Add additional check and troubleshooting
benrobson Apr 27, 2024
5115d0e
Commit
benrobson Apr 27, 2024
0173265
Add a build command.
benrobson May 4, 2024
4082e66
Fix Discord oAuth (#98)
benrobson May 9, 2024
4538a41
Fix issues with loading profile editor.
benrobson May 11, 2024
f2073af
On profile updates, redirect to profile.
benrobson May 11, 2024
f167409
Add steam social and profanity filter to interests.
benrobson May 12, 2024
ed140e8
Add ability for linked accounts to not trigger linking codes.
benrobson May 12, 2024
c411186
Push profile command.
benrobson May 14, 2024
26309fe
Add ranks api to fetch by rank and user.
benrobson May 16, 2024
b4d6c51
Add debug for user permissions
benrobson Aug 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PORT=8080
siteAddress=http://localhost:8080
TZ=Australia/Sydney

discordAPIKey=APIKEY
discordClientId=CLIENTID
discordClientSecret=CLIENTSECRET
apiKey=KEY

sessionCookieSecret=THISISNOTVERYSECRETANDITHINKYOUSHOULDCHANGEIT

databaseHost=database.example.com
databasePort=3306
databaseUser=root
databasePassword=root
databaseName=zander
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ package-lock.json
sslCert.cert
sslPrivate.key
config.json
package-lock.json
google.json
features.json
11 changes: 9 additions & 2 deletions api/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dotenv from "dotenv";
dotenv.config();
import config from "../config.json" assert { type: "json" };
import fetch from "node-fetch";
import { readdirSync } from "fs";
Expand Down Expand Up @@ -129,7 +131,7 @@ export async function hasPermission(permissionNode, req, res, features) {
}

if (!hasSpecificPerm(permissionNode, userPermissions)) {
res.view("session/noPermission", {
return res.view("session/noPermission", {
pageTitle: `Access Restricted`,
config: config,
req: req,
Expand All @@ -138,7 +140,6 @@ export async function hasPermission(permissionNode, req, res, features) {
globalImage: await getGlobalImage(),
announcementWeb: await getWebAnnouncement(),
});
return false;
}
return true;
}
Expand Down Expand Up @@ -170,6 +171,7 @@ export async function postAPIRequest(
"x-access-token": process.env.apiKey,
},
});

const data = await response.json();

console.log(data);
Expand Down Expand Up @@ -311,3 +313,8 @@ export async function expandString(string, filter) {
export function removeHtmlTags(html) {
return html.replace(/<(?!\/?(a)\b)[^<]*?>/gi, "");
}

export async function generateVerifyCode() {
const code = Math.floor(Math.random() * 900000) + 100000;
return code;
}
9 changes: 9 additions & 0 deletions api/internal_redirect/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default function announcementRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/create", async function (req, res) {
if (!hasPermission("zander.web.announcements", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/announcement/create`,
req.body,
Expand All @@ -21,6 +24,9 @@ export default function announcementRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/edit", async function (req, res) {
if (!hasPermission("zander.web.announcements", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/announcement/edit`,
req.body,
Expand All @@ -36,6 +42,9 @@ export default function announcementRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/delete", async function (req, res) {
if (!hasPermission("zander.web.announcements", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/announcement/delete`,
req.body,
Expand Down
9 changes: 9 additions & 0 deletions api/internal_redirect/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default function applicationRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/create", async function (req, res) {
if (!hasPermission("zander.web.application", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/application/create`,
req.body,
Expand All @@ -21,6 +24,9 @@ export default function applicationRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/edit", async function (req, res) {
if (!hasPermission("zander.web.application", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/application/edit`,
req.body,
Expand All @@ -36,6 +42,9 @@ export default function applicationRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/delete", async function (req, res) {
if (!hasPermission("zander.web.application", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/application/delete`,
req.body,
Expand Down
9 changes: 9 additions & 0 deletions api/internal_redirect/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default function serverRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/create", async function (req, res) {
if (!hasPermission("zander.web.server", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/server/create`,
req.body,
Expand All @@ -21,6 +24,9 @@ export default function serverRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/edit", async function (req, res) {
if (!hasPermission("zander.web.server", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/server/edit`,
req.body,
Expand All @@ -36,6 +42,9 @@ export default function serverRedirectRoute(app, config, lang) {
app.post(baseEndpoint + "/delete", async function (req, res) {
if (!hasPermission("zander.web.server", req, res)) return;

// Add userId to req.body
req.body.actioningUser = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/server/delete`,
req.body,
Expand Down
75 changes: 70 additions & 5 deletions api/internal_redirect/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,80 @@ import { postAPIRequest } from "../common";
export default function webRedirectRoute(app, config, lang) {
const baseEndpoint = "/redirect/web";

app.post(baseEndpoint + "/register", async function (req, res) {
await postAPIRequest(
`${process.env.siteAddress}/api/web/register/create`,
app.post(baseEndpoint + "/user/link", async function (req, res) {
postAPIRequest(
`${process.env.siteAddress}/api/user/link`,
req.body,
`${process.env.siteAddress}/register`,
`${process.env.siteAddress}/unregistered`,
res
);

res.redirect(`${process.env.siteAddress}/register`);
res.redirect(`${process.env.siteAddress}/`);

return res;
});

app.post(baseEndpoint + "/user/profile/display", async function (req, res) {
// Add userId to req.body
req.body.userId = req.session.user.userId;

// Make the API request
postAPIRequest(
`${process.env.siteAddress}/api/user/profile/display`,
req.body,
`${process.env.siteAddress}/`,
res
);

res.redirect(`${process.env.siteAddress}/profile/${req.session.user.username}`);

return res;
});

app.post(baseEndpoint + "/user/profile/interests", async function (req, res) {
// Add userId to req.body
req.body.userId = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/user/profile/interests`,
req.body,
`${process.env.siteAddress}/`,
res
);

res.redirect(`${process.env.siteAddress}/profile/${req.session.user.username}`);

return res;
});

app.post(baseEndpoint + "/user/profile/about", async function (req, res) {
// Add userId to req.body
req.body.userId = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/user/profile/about`,
req.body,
`${process.env.siteAddress}/`,
res
);

res.redirect(`${process.env.siteAddress}/profile/${req.session.user.username}`);

return res;
});

app.post(baseEndpoint + "/user/profile/social", async function (req, res) {
// Add userId to req.body
req.body.userId = req.session.user.userId;

postAPIRequest(
`${process.env.siteAddress}/api/user/profile/social`,
req.body,
`${process.env.siteAddress}/`,
res
);

res.redirect(`${process.env.siteAddress}/profile/${req.session.user.username}`);

return res;
});
Expand Down
2 changes: 1 addition & 1 deletion api/routes/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function announcementApiRoute(app, config, db, features, lang) {

app.get(baseEndpoint + "/get", async function (req, res) {
isFeatureEnabled(features.announcements, res, lang);
const announcementId = optional(req.query, "announcementId");
const announcementId = optional(req.query, "id");
const announcementType = optional(req.query, "announcementType");
const enabled = optional(req.query, "enabled");

Expand Down
2 changes: 1 addition & 1 deletion api/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function applicationApiRoute(app, config, db, features, lang) {

app.get(baseEndpoint + "/get", async function (req, res) {
isFeatureEnabled(features.applications, res, lang);
const applicationId = optional(req.query, "applicationId");
const applicationId = optional(req.query, "id");

try {
function getApplications(dbQuery) {
Expand Down
58 changes: 46 additions & 12 deletions api/routes/discord.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { updateAudit_lastMinecraftLogin, updateAudit_lastMinecraftMessage } from "../../controllers/auditController";
import { Webhook } from "discord-webhook-node";
import { isFeatureEnabled, required } from "../common";

Expand Down Expand Up @@ -44,6 +45,21 @@ export default function discordApiRoute(
const server = required(req.body, "server", res);
const content = required(req.body, "content", res);

//
// Update user profile for auditing
//
try {
updateAudit_lastMinecraftMessage(new Date(), username);
} catch (error) {
return res.send({
success: false,
message: `${error}`,
});
}

//
// Send Discord Message to Log
//
try {
const networkChatLogHook = new Webhook(
config.discord.webhooks.networkChatLog
Expand All @@ -66,26 +82,44 @@ export default function discordApiRoute(
isFeatureEnabled(features.discord, res, lang);
const username = required(req.body, "username", res);

try {
const networkChatLogHook = new Webhook(
config.discord.webhooks.networkChatLog
);
//
// Send Discord Message to Log
//
try {
const networkChatLogHook = new Webhook(
config.discord.webhooks.networkChatLog
);

networkChatLogHook.send(
`:ballot_box_with_check: | \`${username}\` has joined the Network.`
);
} catch (error) {
return res.send({
success: false,
message: `${error}`,
});
}
});

networkChatLogHook.send(
`:ballot_box_with_check: | \`${username}\` has joined the Network.`
);
app.post(baseEndpoint + "/leave", async function (req, res) {
isFeatureEnabled(features.discord, res, lang);
const username = required(req.body, "username", res);

//
// Update user profile for auditing
//
try {
updateAudit_lastMinecraftLogin(new Date(), username);
} catch (error) {
return res.send({
success: false,
message: `${error}`,
});
}
});

app.post(baseEndpoint + "/leave", async function (req, res) {
isFeatureEnabled(features.discord, res, lang);
const username = required(req.body, "username", res);

//
// Send Discord Message to Log
//
try {
const networkChatLogHook = new Webhook(
config.discord.webhooks.networkChatLog
Expand Down
2 changes: 2 additions & 0 deletions api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sessionApiRoute from "./session";
import userApiRoute from "./user";
import webApiRoute from "./web";
import filterApiRoute from "./filter";
import rankApiRoute from "./ranks";

export default (app, client, moment, config, db, features, lang) => {
announcementApiRoute(app, config, db, features, lang);
Expand All @@ -15,6 +16,7 @@ export default (app, client, moment, config, db, features, lang) => {
sessionApiRoute(app, config, db, features, lang);
userApiRoute(app, config, db, features, lang);
webApiRoute(app, config, db, features, lang);
rankApiRoute(app, config, db, features, lang);
filterApiRoute(app, config, db, features, lang);

app.get("/api/heartbeat", async function (req, res) {
Expand Down
Loading