summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 12:54:03 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 12:54:03 +0200
commit732f88cbb25f63fff50ea9a56f62a0eccb149c2d (patch)
tree769067bea17bd9b857cc6f2a83837817eff4ef68
parent:bug: fix password changing (diff)
downloadserver-732f88cbb25f63fff50ea9a56f62a0eccb149c2d.tar.xz
:sparkles: added guestsRequireInvite to config
Diffstat (limited to '')
-rw-r--r--api/src/routes/auth/register.ts12
-rw-r--r--util/src/entities/Config.ts2
2 files changed, 9 insertions, 5 deletions
diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts
index 9f3b46f1..4b08e78e 100644
--- a/api/src/routes/auth/register.ts
+++ b/api/src/routes/auth/register.ts
@@ -154,16 +154,18 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
 		});
 	}
 
+	if (!body.invite && (register.requireInvite || (register.guestsRequireInvite && !register.email))) {
+		// require invite to register -> e.g. for organizations to send invites to their employees
+		throw FieldErrors({
+			email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") }
+		});
+	}
+
 	const user = await User.register({ ...body, req });
 
 	if (body.invite) {
 		// await to fail if the invite doesn't exist (necessary for requireInvite to work properly) (username only signups are possible)
 		await Invite.joinGuild(user.id, body.invite);
-	} else if (register.requireInvite) {
-		// require invite to register -> e.g. for organizations to send invites to their employees
-		throw FieldErrors({
-			email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") }
-		});
 	}
 
 	return res.json({ token: await generateToken(user.id) });
diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts
index 921a12c2..813649ac 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -128,6 +128,7 @@ export interface ConfigValue {
 		disabled: boolean;
 		requireCaptcha: boolean;
 		requireInvite: boolean;
+		guestsRequireInvite: boolean;
 		allowNewRegistration: boolean;
 		allowMultipleAccounts: boolean;
 		blockProxies: boolean;
@@ -277,6 +278,7 @@ export const DefaultConfigOptions: ConfigValue = {
 		},
 		disabled: false,
 		requireInvite: false,
+		guestsRequireInvite: true,
 		requireCaptcha: true,
 		allowNewRegistration: true,
 		allowMultipleAccounts: true,