diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-09-18 00:19:09 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-09-18 00:19:09 +0200 |
commit | 6ef6a8a68dabd5863ce62a2944fb5c957d50f0df (patch) | |
tree | 0374971f959eed92fdb11af7d7a9afda4b8f4f00 | |
parent | Cryptographically secure invites, add generation of tokens (diff) | |
download | server-6ef6a8a68dabd5863ce62a2944fb5c957d50f0df.tar.xz |
check token validity + delete invalid, prettier
26 files changed, 152 insertions, 141 deletions
diff --git a/src/api/middlewares/RateLimit.ts b/src/api/middlewares/RateLimit.ts index bb9a334c..b19f9f7e 100644 --- a/src/api/middlewares/RateLimit.ts +++ b/src/api/middlewares/RateLimit.ts @@ -1,5 +1,4 @@ -import { getIpAdress } from "@fosscord/util"; -import { Config, getRights, listenEvent } from "@fosscord/util"; +import { Config, getIpAdress, getRights, listenEvent } from "@fosscord/util"; import { NextFunction, Request, Response, Router } from "express"; import { API_PREFIX_TRAILING_SLASH } from "./Authentication"; diff --git a/src/api/routes/auth/generate-registration-tokens.ts b/src/api/routes/auth/generate-registration-tokens.ts index 322db33c..6f7f8630 100644 --- a/src/api/routes/auth/generate-registration-tokens.ts +++ b/src/api/routes/auth/generate-registration-tokens.ts @@ -1,29 +1,27 @@ import { route } from "@fosscord/api"; -import { Config, random, Rights, ValidRegistrationToken } from "@fosscord/util"; +import { Config, random, ValidRegistrationToken } from "@fosscord/util"; import { Request, Response, Router } from "express"; - const router: Router = Router(); export default router; router.get("/", route({ right: "OPERATOR" }), async (req: Request, res: Response) => { - let count = (req.query.count as unknown) as number ?? 1; - let tokens: string[] = []; - let dbtokens: ValidRegistrationToken[] = []; - for(let i = 0; i < count; i++) { - let token = random((req.query.length as unknown as number) ?? 255); - let vrt = new ValidRegistrationToken(); - vrt.token = token; - dbtokens.push(vrt); - if(req.query.include_url == "true") token = `${Config.get().general.publicUrl}/register?token=${token}`; - tokens.push(token); - } - await ValidRegistrationToken.save(dbtokens, { chunk: 1000, reload: false, transaction: false }); - - if(req.query.plain == "true") { - if(count == 1) res.send(tokens[0]); - else res.send(tokens.join("\n")); - } - else if(count == 1) res.json({ token: tokens[0] }); - else res.json({ tokens }); -}); \ No newline at end of file + let count = (req.query.count as unknown as number) ?? 1; + let tokens: string[] = []; + let dbtokens: ValidRegistrationToken[] = []; + for (let i = 0; i < count; i++) { + let token = random((req.query.length as unknown as number) ?? 255); + let vrt = new ValidRegistrationToken(); + vrt.token = token; + dbtokens.push(vrt); + if (req.query.include_url == "true") token = `${Config.get().general.publicUrl}/register?token=${token}`; + tokens.push(token); + } + await ValidRegistrationToken.save(dbtokens, { chunk: 1000, reload: false, transaction: false }); + + if (req.query.plain == "true") { + if (count == 1) res.send(tokens[0]); + else res.send(tokens.join("\n")); + } else if (count == 1) res.json({ token: tokens[0] }); + else res.json({ tokens }); +}); diff --git a/src/api/routes/auth/location-metadata.ts b/src/api/routes/auth/location-metadata.ts index 4bc7da28..5ccd7e85 100644 --- a/src/api/routes/auth/location-metadata.ts +++ b/src/api/routes/auth/location-metadata.ts @@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import {getIpAdress, IPAnalysis} from "@fosscord/util"; +import { getIpAdress, IPAnalysis } from "@fosscord/util"; import { Request, Response, Router } from "express"; const router = Router(); diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts index bbd9cf93..4c882c14 100644 --- a/src/api/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts @@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { adjustEmail, Config, FieldErrors, generateToken, LoginSchema, User, getIpAdress, verifyCaptcha } from "@fosscord/util"; +import { adjustEmail, Config, FieldErrors, generateToken, getIpAdress, LoginSchema, User, verifyCaptcha } from "@fosscord/util"; import crypto from "crypto"; import { Request, Response, Router } from "express"; diff --git a/src/api/routes/auth/logout.ts b/src/api/routes/auth/logout.ts index b54be044..7e36ae9a 100644 --- a/src/api/routes/auth/logout.ts +++ b/src/api/routes/auth/logout.ts @@ -1,19 +1,16 @@ import { route } from "@fosscord/api"; import { Request, Response, Router } from "express"; - const router: Router = Router(); export default router; router.post("/", route({}), async (req: Request, res: Response) => { - if(req.body.provider != null || req.body.voip_provider != null) { + if (req.body.provider != null || req.body.voip_provider != null) { console.log(`[LOGOUT]: provider or voip provider not null!`, req.body); - } - else { + } else { delete req.body.provider; delete req.body.voip_provider; - if(Object.keys(req.body).length != 0) - console.log(`[LOGOUT]: Extra fields sent in logout!`, req.body); + if (Object.keys(req.body).length != 0) console.log(`[LOGOUT]: Extra fields sent in logout!`, req.body); } res.status(204).send(); -}); \ No newline at end of file +}); diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts index 08e9f7bb..b87c26f6 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts @@ -1,8 +1,22 @@ import { route } from "@fosscord/api"; -import { adjustEmail, Config, FieldErrors, generateToken, HTTPError, Invite, RegisterSchema, User, ValidRegistrationToken, getIpAdress, IPAnalysis, isProxy, verifyCaptcha } from "@fosscord/util"; +import { + adjustEmail, + Config, + FieldErrors, + generateToken, + getIpAdress, + HTTPError, + Invite, + IPAnalysis, + isProxy, + RegisterSchema, + User, + ValidRegistrationToken, + verifyCaptcha +} from "@fosscord/util"; import { Request, Response, Router } from "express"; import { red, yellow } from "picocolors"; -import { MoreThan } from "typeorm"; +import { LessThan, MoreThan } from "typeorm"; let bcrypt: any; try { @@ -133,13 +147,13 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re if (req.get("Referrer") && req.get("Referrer")?.includes("token=")) { let token = req.get("Referrer")?.split("token=")[1].split("&")[0]; if (token) { - let registrationToken = await ValidRegistrationToken.findOne({ where: { token: token } }); + await ValidRegistrationToken.delete({ expires_at: LessThan(new Date()) }); + let registrationToken = await ValidRegistrationToken.findOne({ where: { token: token, expires_at: MoreThan(new Date()) } }); if (registrationToken) { console.log(yellow(`[REGISTER] Registration token ${token} used for registration!`)); await ValidRegistrationToken.delete(token); validToken = true; - } - else { + } else { console.log(yellow(`[REGISTER] Invalid registration token ${token} used for registration by ${ip}!`)); } } diff --git a/src/api/routes/guilds/#guild_id/bans.ts b/src/api/routes/guilds/#guild_id/bans.ts index e4fe605b..4963d36a 100644 --- a/src/api/routes/guilds/#guild_id/bans.ts +++ b/src/api/routes/guilds/#guild_id/bans.ts @@ -5,13 +5,13 @@ import { BanRegistrySchema, DiscordApiErrors, emitEvent, + getIpAdress, GuildBanAddEvent, GuildBanRemoveEvent, HTTPError, Member, OrmUtils, - User, - getIpAdress + User } from "@fosscord/util"; import { Request, Response, Router } from "express"; diff --git a/src/api/routes/guilds/#guild_id/regions.ts b/src/api/routes/guilds/#guild_id/regions.ts index d32ff118..4a5f5eca 100644 --- a/src/api/routes/guilds/#guild_id/regions.ts +++ b/src/api/routes/guilds/#guild_id/regions.ts @@ -1,5 +1,5 @@ import { getVoiceRegions, route } from "@fosscord/api"; -import { Guild, getIpAdress } from "@fosscord/util"; +import { getIpAdress, Guild } from "@fosscord/util"; import { Request, Response, Router } from "express"; const router = Router(); diff --git a/src/api/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts index 1f85cdcf..af116760 100644 --- a/src/api/routes/guilds/#guild_id/templates.ts +++ b/src/api/routes/guilds/#guild_id/templates.ts @@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { Guild, HTTPError, OrmUtils, Template, generateCode } from "@fosscord/util"; +import { generateCode, Guild, HTTPError, OrmUtils, Template } from "@fosscord/util"; import { Request, Response, Router } from "express"; const router: Router = Router(); diff --git a/src/api/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts index e88aa714..6383f3f3 100644 --- a/src/api/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts @@ -179,7 +179,7 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ if (friendRequest) { //TODO: shouldn't this be failed silently? - if (friendRequest.type === RelationshipType.blocked) throw new HTTPError(req.t("common:relationship.BLOCKED")); + if (friendRequest.type === RelationshipType.blocked) throw new HTTPError(req.t("common:relationship.BLOCKED")); if (friendRequest.type === RelationshipType.friends) throw new HTTPError(req.t("common:relationship.ALREADY_FRIENDS")); // accept friend request incoming_relationship = friendRequest as any; //TODO: checkme, any cast diff --git a/src/api/routes/voice/regions.ts b/src/api/routes/voice/regions.ts index 9071fcd5..1b5541e7 100644 --- a/src/api/routes/voice/regions.ts +++ b/src/api/routes/voice/regions.ts @@ -1,6 +1,6 @@ import { getVoiceRegions, route } from "@fosscord/api"; -import { Request, Response, Router } from "express"; import { getIpAdress } from "@fosscord/util"; +import { Request, Response, Router } from "express"; const router: Router = Router(); diff --git a/src/api/util/index.ts b/src/api/util/index.ts index 7223d6f4..46cbd5ba 100644 --- a/src/api/util/index.ts +++ b/src/api/util/index.ts @@ -1,4 +1,4 @@ export * from "./entities/AssetCacheItem"; export * from "./handlers/Message"; export * from "./handlers/route"; -export * from "./handlers/Voice"; \ No newline at end of file +export * from "./handlers/Voice"; diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts index bf74bd73..530d3a8b 100644 --- a/src/cdn/routes/attachments.ts +++ b/src/cdn/routes/attachments.ts @@ -10,7 +10,8 @@ const router = Router(); const SANITIZED_CONTENT_TYPE = ["text/html", "text/mhtml", "multipart/related", "application/xhtml+xml"]; router.post("/:channel_id", multer.single("file"), async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); if (!req.file) throw new HTTPError(req.t("common:body.MISSING_FILE")); const { buffer, mimetype, size, originalname, fieldname } = req.file; @@ -64,7 +65,8 @@ router.get("/:channel_id/:id/:filename", async (req: Request, res: Response) => }); router.delete("/:channel_id/:id/:filename", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); const { channel_id, id, filename } = req.params; const path = `attachments/${channel_id}/${id}/${filename}`; diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts index 1bd91942..2fa88987 100644 --- a/src/cdn/routes/avatars.ts +++ b/src/cdn/routes/avatars.ts @@ -17,7 +17,8 @@ const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES]; const router = Router(); router.post("/:user_id", multer.single("file"), async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); if (!req.file) throw new HTTPError(req.t("common:body.MISSING_FILE")); const { buffer, mimetype, size, originalname, fieldname } = req.file; const { user_id } = req.params; @@ -72,7 +73,8 @@ router.get("/:user_id/:hash", async (req: Request, res: Response) => { }); router.delete("/:user_id/:id", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); const { user_id, id } = req.params; const path = `avatars/${user_id}/${id}`; diff --git a/src/cdn/routes/external.ts b/src/cdn/routes/external.ts index cd25268f..43c4e505 100644 --- a/src/cdn/routes/external.ts +++ b/src/cdn/routes/external.ts @@ -19,7 +19,8 @@ const DEFAULT_FETCH_OPTIONS: any = { }; router.post("/", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); if (!req.body) throw new HTTPError("Invalid Body"); diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts index 9fc3b80f..4ae492ea 100644 --- a/src/cdn/routes/guild-profiles.ts +++ b/src/cdn/routes/guild-profiles.ts @@ -17,7 +17,8 @@ const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES]; const router = Router(); router.post("/", multer.single("file"), async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); if (!req.file) throw new HTTPError(req.t("common:body.MISSING_FILE")); const { buffer, mimetype, size, originalname, fieldname } = req.file; const { guild_id, user_id } = req.params; @@ -72,7 +73,8 @@ router.get("/:hash", async (req: Request, res: Response) => { }); router.delete("/:id", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); const { guild_id, user_id, id } = req.params; const path = `guilds/${guild_id}/users/${user_id}/avatars/${id}`; diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index 4449f9d1..b0946eaa 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -17,7 +17,8 @@ const ALLOWED_MIME_TYPES = [...STATIC_MIME_TYPES]; const router = Router(); router.post("/:role_id", multer.single("file"), async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); if (!req.file) throw new HTTPError(req.t("common:body.MISSING_FILE")); const { buffer, mimetype, size, originalname, fieldname } = req.file; const { role_id } = req.params; @@ -71,7 +72,8 @@ router.get("/:role_id/:hash", async (req: Request, res: Response) => { }); router.delete("/:role_id/:id", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); const { role_id, id } = req.params; const path = `role-icons/${role_id}/${id}`; diff --git a/src/util/entities/index.ts b/src/util/entities/index.ts index 673aac36..5342d951 100644 --- a/src/util/entities/index.ts +++ b/src/util/entities/index.ts @@ -29,6 +29,6 @@ export * from "./TeamMember"; export * from "./Template"; export * from "./User"; export * from "./UserSettings"; +export * from "./ValidRegistrationTokens"; export * from "./VoiceState"; export * from "./Webhook"; -export * from "./ValidRegistrationTokens"; \ No newline at end of file diff --git a/src/util/migrations/mariadb/1663440589234-registration_tokens.ts b/src/util/migrations/mariadb/1663440589234-registration_tokens.ts index 12690ac4..364f8668 100644 --- a/src/util/migrations/mariadb/1663440589234-registration_tokens.ts +++ b/src/util/migrations/mariadb/1663440589234-registration_tokens.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class registrationTokens1663440589234 implements MigrationInterface { - name = 'registrationTokens1663440589234' + name = "registrationTokens1663440589234"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` CREATE TABLE \`valid_registration_tokens\` ( \`id\` varchar(255) NOT NULL, \`token\` varchar(255) NOT NULL, @@ -13,19 +13,18 @@ export class registrationTokens1663440589234 implements MigrationInterface { PRIMARY KEY (\`id\`) ) ENGINE = InnoDB `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`users\` DROP COLUMN \`notes\` `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE \`users\` ADD \`notes\` text NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE \`valid_registration_tokens\` `); - } - + } } diff --git a/src/util/migrations/mariadb/1663448562034-drop_id_for_registration_tokens.ts b/src/util/migrations/mariadb/1663448562034-drop_id_for_registration_tokens.ts index d4b13abb..58743d07 100644 --- a/src/util/migrations/mariadb/1663448562034-drop_id_for_registration_tokens.ts +++ b/src/util/migrations/mariadb/1663448562034-drop_id_for_registration_tokens.ts @@ -1,33 +1,32 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class dropIdForRegistrationTokens1663448562034 implements MigrationInterface { - name = 'dropIdForRegistrationTokens1663448562034' + name = "dropIdForRegistrationTokens1663448562034"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` DROP PRIMARY KEY `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` DROP COLUMN \`id\` `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` ADD PRIMARY KEY (\`token\`) `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` DROP PRIMARY KEY `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` ADD \`id\` varchar(255) NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE \`valid_registration_tokens\` ADD PRIMARY KEY (\`id\`) `); - } - + } } diff --git a/src/util/migrations/postgres/1663440587650-registration_tokens.ts b/src/util/migrations/postgres/1663440587650-registration_tokens.ts index a794262c..d5f602b8 100644 --- a/src/util/migrations/postgres/1663440587650-registration_tokens.ts +++ b/src/util/migrations/postgres/1663440587650-registration_tokens.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class registrationTokens1663440587650 implements MigrationInterface { - name = 'registrationTokens1663440587650' + name = "registrationTokens1663440587650"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` CREATE TABLE "valid_registration_tokens" ( "id" character varying NOT NULL, "token" character varying NOT NULL, @@ -13,21 +13,20 @@ export class registrationTokens1663440587650 implements MigrationInterface { CONSTRAINT "PK_aac42a46cd46369450217de1c8a" PRIMARY KEY ("id") ) `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "members" ALTER COLUMN "bio" DROP DEFAULT `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE "members" ALTER COLUMN "bio" SET DEFAULT '' `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "valid_registration_tokens" `); - } - + } } diff --git a/src/util/migrations/postgres/1663448561249-drop_id_for_registration_tokens.ts b/src/util/migrations/postgres/1663448561249-drop_id_for_registration_tokens.ts index ce4b72f4..4dc8c6ba 100644 --- a/src/util/migrations/postgres/1663448561249-drop_id_for_registration_tokens.ts +++ b/src/util/migrations/postgres/1663448561249-drop_id_for_registration_tokens.ts @@ -1,33 +1,32 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class dropIdForRegistrationTokens1663448561249 implements MigrationInterface { - name = 'dropIdForRegistrationTokens1663448561249' + name = "dropIdForRegistrationTokens1663448561249"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" DROP CONSTRAINT "PK_aac42a46cd46369450217de1c8a" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" DROP COLUMN "id" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" ADD CONSTRAINT "PK_e0f5c8e3fcefe3134a092c50485" PRIMARY KEY ("token") `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" DROP CONSTRAINT "PK_e0f5c8e3fcefe3134a092c50485" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" ADD "id" character varying NOT NULL `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" ADD CONSTRAINT "PK_aac42a46cd46369450217de1c8a" PRIMARY KEY ("id") `); - } - + } } diff --git a/src/util/migrations/sqlite/1663440585960-registration_tokens.ts b/src/util/migrations/sqlite/1663440585960-registration_tokens.ts index daf76be6..520977c7 100644 --- a/src/util/migrations/sqlite/1663440585960-registration_tokens.ts +++ b/src/util/migrations/sqlite/1663440585960-registration_tokens.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class registrationTokens1663440585960 implements MigrationInterface { - name = 'registrationTokens1663440585960' + name = "registrationTokens1663440585960"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` CREATE TABLE "valid_registration_tokens" ( "id" varchar PRIMARY KEY NOT NULL, "token" varchar NOT NULL, @@ -12,7 +12,7 @@ export class registrationTokens1663440585960 implements MigrationInterface { "expires_at" datetime NOT NULL ) `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_users" ( "id" varchar PRIMARY KEY NOT NULL, "username" varchar NOT NULL, @@ -49,7 +49,7 @@ export class registrationTokens1663440585960 implements MigrationInterface { CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_users"( "id", "username", @@ -116,21 +116,21 @@ export class registrationTokens1663440585960 implements MigrationInterface { "settingsId" FROM "users" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "users" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_users" RENAME TO "users" `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE "users" RENAME TO "temporary_users" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "users" ( "id" varchar PRIMARY KEY NOT NULL, "username" varchar NOT NULL, @@ -168,7 +168,7 @@ export class registrationTokens1663440585960 implements MigrationInterface { CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "users"( "id", "username", @@ -235,12 +235,11 @@ export class registrationTokens1663440585960 implements MigrationInterface { "settingsId" FROM "temporary_users" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_users" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "valid_registration_tokens" `); - } - + } } diff --git a/src/util/migrations/sqlite/1663448560501-drop_id_for_registration_tokens.ts b/src/util/migrations/sqlite/1663448560501-drop_id_for_registration_tokens.ts index 087cc81f..f99f2348 100644 --- a/src/util/migrations/sqlite/1663448560501-drop_id_for_registration_tokens.ts +++ b/src/util/migrations/sqlite/1663448560501-drop_id_for_registration_tokens.ts @@ -1,80 +1,80 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class dropIdForRegistrationTokens1663448560501 implements MigrationInterface { - name = 'dropIdForRegistrationTokens1663448560501' + name = "dropIdForRegistrationTokens1663448560501"; - public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` CREATE TABLE "temporary_valid_registration_tokens" ( "token" varchar NOT NULL, "created_at" datetime NOT NULL, "expires_at" datetime NOT NULL ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_valid_registration_tokens"("token", "created_at", "expires_at") SELECT "token", "created_at", "expires_at" FROM "valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_valid_registration_tokens" RENAME TO "valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "temporary_valid_registration_tokens" ( "token" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL, "expires_at" datetime NOT NULL ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "temporary_valid_registration_tokens"("token", "created_at", "expires_at") SELECT "token", "created_at", "expires_at" FROM "valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "temporary_valid_registration_tokens" RENAME TO "valid_registration_tokens" `); - } + } - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query(` + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" RENAME TO "temporary_valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "valid_registration_tokens" ( "token" varchar NOT NULL, "created_at" datetime NOT NULL, "expires_at" datetime NOT NULL ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "valid_registration_tokens"("token", "created_at", "expires_at") SELECT "token", "created_at", "expires_at" FROM "temporary_valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` ALTER TABLE "valid_registration_tokens" RENAME TO "temporary_valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` CREATE TABLE "valid_registration_tokens" ( "id" varchar PRIMARY KEY NOT NULL, "token" varchar NOT NULL, @@ -82,16 +82,15 @@ export class dropIdForRegistrationTokens1663448560501 implements MigrationInterf "expires_at" datetime NOT NULL ) `); - await queryRunner.query(` + await queryRunner.query(` INSERT INTO "valid_registration_tokens"("token", "created_at", "expires_at") SELECT "token", "created_at", "expires_at" FROM "temporary_valid_registration_tokens" `); - await queryRunner.query(` + await queryRunner.query(` DROP TABLE "temporary_valid_registration_tokens" `); - } - + } } diff --git a/src/util/util/String.ts b/src/util/util/String.ts index cd5cb4f2..b14cd257 100644 --- a/src/util/util/String.ts +++ b/src/util/util/String.ts @@ -1,7 +1,7 @@ -import { SPECIAL_CHAR } from "./Regex"; import { FieldErrors } from "@fosscord/util"; import { Request } from "express"; import { ntob } from "./Base64"; +import { SPECIAL_CHAR } from "./Regex"; export function checkLength(str: string, min: number, max: number, key: string, req: Request) { if (str.length < min || str.length > max) { diff --git a/src/util/util/index.ts b/src/util/util/index.ts index 1ef7467c..e10dc563 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts @@ -1,6 +1,7 @@ export * from "./ApiError"; export * from "./Array"; export * from "./BitField"; +export * from "./Captcha"; //export * from "./Categories"; export * from "./CDN"; export * from "./Config"; @@ -14,15 +15,14 @@ export * from "./imports/index"; export * from "./imports/OrmUtils"; export * from "./Intents"; export * from "./InvisibleCharacters"; +export * from "./IPAddress"; export * from "./MessageFlags"; export * from "./Permissions"; export * from "./RabbitMQ"; +export * from "./RandomInviteID"; export * from "./Regex"; export * from "./Rights"; export * from "./Snowflake"; export * from "./String"; export * from "./Token"; export * from "./TraverseDirectory"; -export * from "./IPAddress"; -export * from "./RandomInviteID"; -export * from "./Captcha"; \ No newline at end of file |