summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-27 03:54:58 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-27 03:58:16 +0200
commit204aa024dc61e47c13116d194fd6217b33687be5 (patch)
tree38f7579934ccb115b3ab509b61a75ccf6db09601
parentMerge remote-tracking branch 'Maddy/fix/categoryNames' into staging (diff)
parentMerge remote-tracking branch 'upstream/staging' into fix/claim_accounts (diff)
downloadserver-204aa024dc61e47c13116d194fd6217b33687be5.tar.xz
Merge remote-tracking branch 'Maddy/fix/claim_accounts' into staging
-rw-r--r--assets/locales/en/auth.json3
-rw-r--r--assets/schemas.json3
-rw-r--r--src/api/routes/auth/register.ts16
-rw-r--r--src/api/routes/users/@me/index.ts9
-rw-r--r--src/util/config/types/RegisterConfiguration.ts1
-rw-r--r--src/util/schemas/UserModifySchema.ts1
6 files changed, 27 insertions, 6 deletions
diff --git a/assets/locales/en/auth.json b/assets/locales/en/auth.json
index a78d4d60..b6264a43 100644
--- a/assets/locales/en/auth.json
+++ b/assets/locales/en/auth.json
@@ -13,6 +13,7 @@
 		"EMAIL_ALREADY_REGISTERED": "Email is already registered",
 		"DATE_OF_BIRTH_UNDERAGE": "You need to be {{years}} years or older",
 		"CONSENT_REQUIRED": "You must agree to the Terms of Service and Privacy Policy.",
-		"USERNAME_TOO_MANY_USERS": "Too many users have this username, please try another"
+		"USERNAME_TOO_MANY_USERS": "Too many users have this username, please try another",
+		"GUESTS_DISABLED": "Guest users are disabled"
 	}
 }
diff --git a/assets/schemas.json b/assets/schemas.json
index e3200800..05650a4e 100644
--- a/assets/schemas.json
+++ b/assets/schemas.json
@@ -1105,6 +1105,9 @@
 			},
 			"code": {
 				"type": "string"
+			},
+			"email": {
+				"type": "string"
 			}
 		},
 		"additionalProperties": false,
diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts
index d3b5a59c..5cc28f7a 100644
--- a/src/api/routes/auth/register.ts
+++ b/src/api/routes/auth/register.ts
@@ -1,6 +1,6 @@
+import { getIpAdress, IPAnalysis, isProxy, route, verifyCaptcha } from "@fosscord/api";
+import { adjustEmail, Config, FieldErrors, generateToken, HTTPError, Invite, RegisterSchema, User } from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, RegisterSchema } from "@fosscord/util";
-import { route, getIpAdress, IPAnalysis, isProxy, verifyCaptcha } from "@fosscord/api";
 
 let bcrypt: any;
 try {
@@ -9,7 +9,6 @@ try {
 	bcrypt = require("bcryptjs");
 	console.log("Warning: using bcryptjs because bcrypt is not installed! Performance will be affected.");
 }
-import { HTTPError } from "@fosscord/util";
 
 const router: Router = Router();
 
@@ -44,6 +43,12 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
 		});
 	}
 
+	if (!register.allowGuests) {
+		throw FieldErrors({
+			email: { code: "GUESTS_DISABLED", message: req.t("auth:register.GUESTS_DISABLED") }
+		});
+	}
+
 	if (register.requireCaptcha && security.captcha.enabled) {
 		const { sitekey, service } = security.captcha;
 		if (!body.captcha_key) {
@@ -60,7 +65,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
 				captcha_key: verify["error-codes"],
 				captcha_sitekey: sitekey,
 				captcha_service: service
-			})
+			});
 		}
 	}
 
@@ -111,7 +116,8 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
 		});
 	}
 
-	if (register.dateOfBirth.required && !body.date_of_birth) {
+	// If no password is provided, this is a guest account
+	if (register.dateOfBirth.required && !body.date_of_birth && body.password) {
 		throw FieldErrors({
 			date_of_birth: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
 		});
diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts
index fcb0a9df..563300dc 100644
--- a/src/api/routes/users/@me/index.ts
+++ b/src/api/routes/users/@me/index.ts
@@ -1,5 +1,7 @@
 import { route } from "@fosscord/api";
 import {
+	adjustEmail,
+	Config,
 	emitEvent,
 	FieldErrors,
 	generateToken,
@@ -45,6 +47,13 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
 		}
 	}
 
+	if (body.email) {
+		body.email = adjustEmail(body.email);
+		if (!body.email && Config.get().register.email.required)
+			throw FieldErrors({ email: { message: req.t("auth:register.EMAIL_INVALID"), code: "EMAIL_INVALID" } });
+		if (!body.password) throw FieldErrors({ password: { message: req.t("auth:register.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
+	}
+
 	if (body.new_password) {
 		if (!body.password && !user.email) {
 			throw FieldErrors({
diff --git a/src/util/config/types/RegisterConfiguration.ts b/src/util/config/types/RegisterConfiguration.ts
index 939605a6..68946272 100644
--- a/src/util/config/types/RegisterConfiguration.ts
+++ b/src/util/config/types/RegisterConfiguration.ts
@@ -9,6 +9,7 @@ export class RegisterConfiguration {
 	disabled: boolean = false;
 	requireCaptcha: boolean = true;
 	requireInvite: boolean = false;
+	allowGuests: boolean = true;
 	guestsRequireInvite: boolean = true;
 	allowNewRegistration: boolean = true;
 	allowMultipleAccounts: boolean = true;
diff --git a/src/util/schemas/UserModifySchema.ts b/src/util/schemas/UserModifySchema.ts
index d69f83f4..622497d9 100644
--- a/src/util/schemas/UserModifySchema.ts
+++ b/src/util/schemas/UserModifySchema.ts
@@ -15,4 +15,5 @@ export interface UserModifySchema {
 	password?: string;
 	new_password?: string;
 	code?: string;
+	email?: string;
 }