From d1844b65d147022d1c848d368f893af3c5603f77 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 9 Oct 2021 12:54:03 +0200 Subject: :sparkles: added guestsRequireInvite to config --- api/src/routes/auth/register.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'api/src/routes/auth') 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) }); -- cgit 1.5.1 From de681188e5513359f3036138b517e42a3b78fb92 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 9 Oct 2021 14:00:28 +0200 Subject: :bug: fix typing --- api/src/routes/auth/register.ts | 3 ++- api/src/routes/channels/#channel_id/typing.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'api/src/routes/auth') diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts index 4b08e78e..cd1bcb72 100644 --- a/api/src/routes/auth/register.ts +++ b/api/src/routes/auth/register.ts @@ -98,7 +98,6 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re } } - console.log("register", body.email, body.username, ip); // TODO: gift_code_sku_id? // TODO: check password strength @@ -168,6 +167,8 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re await Invite.joinGuild(user.id, body.invite); } + console.log("register", body.email, body.username, ip); + return res.json({ token: await generateToken(user.id) }); }); diff --git a/api/src/routes/channels/#channel_id/typing.ts b/api/src/routes/channels/#channel_id/typing.ts index a9dcb315..45ed76db 100644 --- a/api/src/routes/channels/#channel_id/typing.ts +++ b/api/src/routes/channels/#channel_id/typing.ts @@ -9,7 +9,7 @@ router.post("/", route({ permission: "SEND_MESSAGES" }), async (req: Request, re const user_id = req.user_id; const timestamp = Date.now(); const channel = await Channel.findOneOrFail({ id: channel_id }); - const member = await Member.findOneOrFail({ where: { id: user_id }, relations: ["roles"] }); + const member = await Member.findOneOrFail({ where: { id: user_id }, relations: ["roles", "user"] }); await emitEvent({ event: "TYPING_START", -- cgit 1.5.1