🎨 added optional captcha to login route

This commit is contained in:
Flam3rboy
2021-05-01 13:54:12 +02:00
parent 5e9fb8a2a2
commit bbeab4da65
8 changed files with 64 additions and 37 deletions
+16 -1
View File
@@ -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) {