Skip to content
Snippets Groups Projects
Commit 14015947 authored by Eric Bieszczad-Stie's avatar Eric Bieszczad-Stie :weary:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #138708 failed
old_project_as_template/*
dist/*
node_modules/*
\ No newline at end of file
{
"name": "discord-verification-feide",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"watch": "npx tsc -w",
"dev": "nodemon dist/index.js",
"build": "npx tsc"
},
"license": "MIT",
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^16.7.1",
"nodemon": "^2.0.12",
"typescript": "^4.3.5"
},
"dependencies": {
"@mikro-orm/cli": "^4.5.9",
"@mikro-orm/core": "^4.5.9",
"@mikro-orm/migrations": "^4.5.9",
"@mikro-orm/postgresql": "^4.5.9",
"express": "^4.17.1",
"pg": "^8.7.1"
}
}
import { Entity, PrimaryKey, Property, Unique } from "@mikro-orm/core";
@Entity()
export class DiscordUser {
@PrimaryKey()
discordId!: number;
@Property()
@Unique()
feideId!: number;
@Property({ type: "date" })
createdAt: Date = new Date();
@Property({ type: "date", onUpdate: () => new Date() })
updatedAt: Date = new Date();
}
\ No newline at end of file
import { MikroORM } from "@mikro-orm/core";
import express from "express";
import path from "path";
import microConfig from "./mikro-orm.config";
const main = async () => {
const orm = await MikroORM.init(microConfig);
await orm.getMigrator().up();
const app = express();
app.use(express.static(path.join(__dirname, "/pages/public/")));
app.get('/', (_, res) => {
res.sendFile(path.join(__dirname, "pages/index.html"));
});
app.get('/feide-auth', (req, res) => {
console.log(req.query);
// Get feide auth code here and validate it
res.send("You will be redirected...");
// Get user data from feide api, then send them back to home page with feide ID
// and feide name in URL encoded parameters for the client to store
});
app.listen(4000, () => {
console.log("Listening on localhost:4000");
});
}
main();
\ No newline at end of file
import { Migration } from '@mikro-orm/migrations';
export class Migration20210826015129 extends Migration {
async up(): Promise<void> {
this.addSql('create table "discord_user" ("discord_id" serial primary key, "feide_id" int4 not null, "created_at" timestamptz(0) not null, "updated_at" timestamptz(0) not null);');
this.addSql('alter table "discord_user" add constraint "discord_user_feide_id_unique" unique ("feide_id");');
}
}
import { MikroORM } from "@mikro-orm/core";
import path from "path";
import { DiscordUser } from "./entities/DiscordUser";
export default {
entities: [DiscordUser],
migrations: {
path: path.join(__dirname, "./migrations"),
pattern: /^[\w-]+\d+\.[tj]s$/,
},
dbName: "DiscordAuthenticationDatabase",
type: "postgresql",
debug: true,
} as Parameters<typeof MikroORM.init>[0];
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Discord Verification - IDATT1001</title>
<link rel="stylesheet" href="/main.css">
</head>
<body>
<div id="container">
<div id="discordAuthenticationDiv" class="authbox"></div>
<div id="feideAuthenticationDiv" class="authbox"></div>
</div>
<script src="/main.js"></script>
</body>
</html>
\ No newline at end of file
body {
height: 100vh; width: 100vw;
overflow: hidden;
background: linear-gradient(45deg, #a3ecf9, #8f12f7);
min-width: 500px;
}
#container {
width: 80%; height: 90%;
background-color: #424149;
border-radius: 50px;
position: fixed;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
display: flex;
}
.authbox {
padding: 25px;
}
#discordAuthenticationDiv {
display: flex;
flex: 1;
border-radius: 50px 0 0 50px;
transition-duration: 1s;
}
#feideAuthenticationDiv {
display: flex;
flex: 1;
border-left: 1px solid black;
}
.leftComplete {
box-shadow: -50px 0 50px rgb(7, 250, 7);
}
.rightComplete {
box-shadow: 50px 0 50px rgb(7, 250, 7);
}
@media screen and (max-width: 992px) {
#container {
flex-direction: column;
}
#feideAuthenticationDiv {
border-left: 0;
border-top: 1px solid black;
}
}
\ No newline at end of file
// Encapsulate and keep variables in this scope
function main() {
var dataFields = window.location.search;
var keyValuePairs = dataFields.substring(1).split("&");
// Get values from url query parameters
var discordValues = {}
keyValuePairs.forEach(keyvalue => {
// Split at the FIRST = and keep the rest (value) intact
// regardless of the amount of = symbols in the value
split = keyvalue.split("=");
key = split.shift();
value = split.join("=");
discordValues[key] = value;
});
checkDiscordCredentials();
function checkDiscordCredentials() {
var { discordImg, discordName, discordId } = discordValues;
if (!(discordImg && discordName && discordId)) {
[ img, name, id ] = [
window.localStorage.getItem("discordImg"),
window.localStorage.getItem("discordName"),
window.localStorage.getItem("discordId")
]
if (img && name && id) {
return setDiscordLoggedIn(img, name, id);
}
return setDiscordOauth();
}
}
function setDiscordLoggedIn(img, name, id) {
var mainDiv = document.createElement("div");
var img = document.createElement("img");
var name = document.createElement("p");
img.src = img;
name.innerText = name;
mainDiv.appendChild(img);
mainDiv.appendChild(name);
document.querySelector("#discordAuthenticationDiv").appendChild(mainDiv);
}
function setDiscordOauth() {
// Puts in a div element with instructions on how to authenticate
// using discord oauth
}
}
main();
\ No newline at end of file
GET http://localhost:4000/feide-auth?code=thisisatestcode
###
GET http://localhost:4000/discord-auth?code=thisisatestcode
\ No newline at end of file
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"baseUrl": "."
},
"exclude": ["node_modules", "./src/rest.http"],
"include": ["./src/"]
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment