diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-20 15:30:50 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-20 15:30:50 +1000 |
commit | 81e570caa2c3cc72d107b986ec9dabf9448a3e0b (patch) | |
tree | b56553c9dfc100c1db8c1b9bc5ea9c60c89c1f2d /api/src/routes/auth/register.ts | |
parent | chore: fix package.json scripts (diff) | |
download | server-81e570caa2c3cc72d107b986ec9dabf9448a3e0b.tar.xz |
Captcha checking
Diffstat (limited to 'api/src/routes/auth/register.ts')
-rw-r--r-- | api/src/routes/auth/register.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts index 94dd6502..98c8fd1b 100644 --- a/api/src/routes/auth/register.ts +++ b/api/src/routes/auth/register.ts @@ -1,6 +1,6 @@ import { Request, Response, Router } from "express"; -import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, trimSpecial } from "@fosscord/util"; -import { route, getIpAdress, IPAnalysis, isProxy } from "@fosscord/api"; +import { Config, generateToken, Invite, FieldErrors, User, adjustEmail } from "@fosscord/util"; +import { route, getIpAdress, IPAnalysis, isProxy, verifyCaptcha } from "@fosscord/api"; import "missing-native-js-functions"; import bcrypt from "bcrypt"; import { HTTPError } from "lambert-server"; @@ -65,8 +65,8 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re } if (register.requireCaptcha && security.captcha.enabled) { + const { sitekey, service } = security.captcha; if (!body.captcha_key) { - const { sitekey, service } = security.captcha; return res?.status(400).json({ captcha_key: ["captcha-required"], captcha_sitekey: sitekey, @@ -74,7 +74,14 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re }); } - // TODO: check captcha + const verify = await verifyCaptcha(body.captcha_key, ip); + if (!verify.success) { + return res.status(400).json({ + captcha_key: verify["error-codes"], + captcha_sitekey: sitekey, + captcha_service: service + }) + } } if (!register.allowMultipleAccounts) { |