summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-05 01:13:05 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-05 01:13:05 +1000
commit3877a404a164c0bc4ff03708fde32555084f8119 (patch)
treec360402246a8125d251f5f69d8c0a4ba51859def
parentMerge branch 'feat/offlineMembers' into slowcord (diff)
downloadserver-3877a404a164c0bc4ff03708fde32555084f8119.tar.xz
Moved slowcord login server to own dir
-rw-r--r--slowcord/build/index.js128
-rw-r--r--slowcord/build/index.js.map1
-rw-r--r--slowcord/login/.env.template (renamed from slowcord/.env.template)0
-rw-r--r--slowcord/login/README.md (renamed from slowcord/README.md)0
-rw-r--r--slowcord/login/package-lock.json (renamed from slowcord/package-lock.json)0
-rw-r--r--slowcord/login/package.json (renamed from slowcord/package.json)0
-rw-r--r--slowcord/login/public/css/index.css (renamed from slowcord/public/css/index.css)0
-rw-r--r--slowcord/login/public/login.html (renamed from slowcord/public/login.html)0
-rw-r--r--slowcord/login/public/register.html (renamed from slowcord/public/register.html)0
-rw-r--r--slowcord/login/src/index.ts (renamed from slowcord/src/index.ts)0
-rw-r--r--slowcord/login/tsconfig.json (renamed from slowcord/tsconfig.json)0
11 files changed, 0 insertions, 129 deletions
diff --git a/slowcord/build/index.js b/slowcord/build/index.js
deleted file mode 100644
index 9a85c188..00000000
--- a/slowcord/build/index.js
+++ /dev/null
@@ -1,128 +0,0 @@
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
-    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
-    return new (P || (P = Promise))(function (resolve, reject) {
-        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
-        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
-        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
-        step((generator = generator.apply(thisArg, _arguments || [])).next());
-    });
-};
-var _a;
-import "dotenv/config";
-import express from "express";
-import cookieParser from "cookie-parser";
-import { initDatabase, generateToken, User, Config } from "@fosscord/util";
-import path from "path";
-import fetch from "node-fetch";
-// apparently dirname doesn't exist in modules, nice
-/* https://stackoverflow.com/a/62892482 */
-import { fileURLToPath } from "url";
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = path.dirname(__filename);
-const app = express();
-app.use(cookieParser());
-const port = process.env.PORT;
-// ip -> unix epoch that requests will be accepted again
-const rateLimits = {};
-const allowRequestsEveryMs = 0.5 * 1000; // every half second
-const allowedRequestsPerSecond = 50;
-let requestsThisSecond = 0;
-setInterval(() => {
-    requestsThisSecond = 0;
-}, 1000);
-class Discord {
-}
-_a = Discord;
-Discord.getAccessToken = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
-    const { code } = req.query;
-    const body = new URLSearchParams(Object.entries({
-        client_id: process.env.DISCORD_CLIENT_ID,
-        client_secret: process.env.DISCORD_SECRET,
-        redirect_uri: process.env.DISCORD_REDIRECT,
-        code: code,
-        grant_type: "authorization_code",
-    })).toString();
-    const resp = yield fetch("https://discord.com/api/oauth2/token", {
-        method: "POST",
-        headers: {
-            "Content-Type": "application/x-www-form-urlencoded",
-        },
-        body: body
-    });
-    const json = yield resp.json();
-    if (json.error)
-        return null;
-    return {
-        access_token: json.access_token,
-        token_type: json.token_type,
-        expires_in: json.expires_in,
-        refresh_token: json.refresh_token,
-        scope: json.scope,
-    };
-});
-Discord.getUserDetails = (token) => __awaiter(void 0, void 0, void 0, function* () {
-    const resp = yield fetch("https://discord.com/api/users/@me", {
-        headers: {
-            "Authorization": `Bearer ${token}`,
-        }
-    });
-    const json = yield resp.json();
-    if (!json.username || !json.email)
-        return null; // eh, deal with bad code later
-    return {
-        id: json.id,
-        email: json.email,
-        username: json.username,
-    };
-});
-const handlers = {
-    "discord": Discord,
-};
-app.get("/oauth/:type", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
-    requestsThisSecond++;
-    if (requestsThisSecond > allowedRequestsPerSecond)
-        return res.sendStatus(429);
-    const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress;
-    console.log(`${ip}`);
-    if (!rateLimits[ip]) {
-        rateLimits[ip] = Date.now() + allowRequestsEveryMs;
-    }
-    else if (rateLimits[ip] > Date.now()) {
-        rateLimits[ip] += allowRequestsEveryMs;
-        console.log(`${new Date()} : user ${ip} was timed out for ${(rateLimits[ip] - Date.now()) / 1000}s`);
-        return res.sendStatus(429);
-    }
-    else {
-        delete rateLimits[ip];
-    }
-    const { type } = req.params;
-    const handler = handlers[type];
-    if (!type || !handler)
-        return res.sendStatus(400);
-    const data = yield handler.getAccessToken(req, res);
-    if (!data)
-        return res.sendStatus(500);
-    const details = yield handler.getUserDetails(data.access_token);
-    if (!details)
-        return res.sendStatus(500);
-    let user = yield User.findOne({ where: { email: details.email } });
-    if (!user) {
-        user = yield User.register({
-            email: details.email,
-            username: details.username,
-            req
-        });
-    }
-    const token = yield generateToken(user.id);
-    res.cookie("token", token);
-    res.sendFile(path.join(__dirname, "../public/login.html"));
-}));
-app.use(express.static("public", { extensions: ["html"] }));
-(() => __awaiter(void 0, void 0, void 0, function* () {
-    yield initDatabase();
-    yield Config.init();
-    app.listen(port, () => {
-        console.log(`Listening on port ${port}`);
-    });
-}))();
-//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/slowcord/build/index.js.map b/slowcord/build/index.js.map
deleted file mode 100644
index c28af385..00000000
--- a/slowcord/build/index.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OA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G,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnE,IAAI,CAAC,IAAI,EAAE;QACV,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC;YAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,GAAG;SACH,CAAC,CAAC;KACH;IAED,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE3C,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE3B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAA,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5D,CAAC,GAAS,EAAE;IACX,MAAM,YAAY,EAAE,CAAC;IACrB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IAEpB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QACrB,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAA,CAAC,EAAE,CAAC"}
\ No newline at end of file
diff --git a/slowcord/.env.template b/slowcord/login/.env.template
index 34f6abeb..34f6abeb 100644
--- a/slowcord/.env.template
+++ b/slowcord/login/.env.template
diff --git a/slowcord/README.md b/slowcord/login/README.md
index 892b5763..892b5763 100644
--- a/slowcord/README.md
+++ b/slowcord/login/README.md
diff --git a/slowcord/package-lock.json b/slowcord/login/package-lock.json
index 7ec24a87..7ec24a87 100644
--- a/slowcord/package-lock.json
+++ b/slowcord/login/package-lock.json
diff --git a/slowcord/package.json b/slowcord/login/package.json
index ba26b1a9..ba26b1a9 100644
--- a/slowcord/package.json
+++ b/slowcord/login/package.json
diff --git a/slowcord/public/css/index.css b/slowcord/login/public/css/index.css
index 1fa76966..1fa76966 100644
--- a/slowcord/public/css/index.css
+++ b/slowcord/login/public/css/index.css
diff --git a/slowcord/public/login.html b/slowcord/login/public/login.html
index ef2d91c1..ef2d91c1 100644
--- a/slowcord/public/login.html
+++ b/slowcord/login/public/login.html
diff --git a/slowcord/public/register.html b/slowcord/login/public/register.html
index 5843649c..5843649c 100644
--- a/slowcord/public/register.html
+++ b/slowcord/login/public/register.html
diff --git a/slowcord/src/index.ts b/slowcord/login/src/index.ts
index 45fbea7d..45fbea7d 100644
--- a/slowcord/src/index.ts
+++ b/slowcord/login/src/index.ts
diff --git a/slowcord/tsconfig.json b/slowcord/login/tsconfig.json
index b8a5965d..b8a5965d 100644
--- a/slowcord/tsconfig.json
+++ b/slowcord/login/tsconfig.json