summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-01 13:54:12 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-01 13:54:12 +0200
commitbbeab4da65c245cb6083554a44fa12293902424d (patch)
treed964467f79a2abe45eeacd9dd35d9d2670ce99ff /src/routes
parent:sparkles: Channel get Route (diff)
downloadserver-ts-bbeab4da65c245cb6083554a44fa12293902424d.tar.xz
:art: added optional captcha to login route
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/auth/login.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/routes/auth/login.ts b/src/routes/auth/login.ts

index 5c43db1b..a0fc1190 100644 --- a/src/routes/auth/login.ts +++ b/src/routes/auth/login.ts
@@ -20,11 +20,26 @@ router.post( $gift_code_sku_id: String, }), async (req: Request, res: Response) => { - const { login, password } = req.body; + const { login, password, captcha_key } = req.body; const email = adjustEmail(login); const query: any[] = [{ phone: login }]; if (email) query.push({ email }); + const config = Config.get(); + + if (config.login.requireCaptcha && config.security.captcha.enabled) { + if (!captcha_key) { + const { sitekey, service } = config.security.captcha; + return res.status(400).json({ + captcha_key: ["captcha-required"], + captcha_sitekey: sitekey, + captcha_service: service, + }); + } + + // TODO: check captcha + } + const user = await UserModel.findOne({ $or: query }, `user_data.hash id user_settings.locale user_settings.theme`).exec(); if (!user) {