add messages of failed captchas to chat
This commit is contained in:
parent
cc49c7d4dd
commit
c5cbe94d50
|
@ -380,7 +380,7 @@ export class ChatProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!user.userlvl && await cheapDetector(user.ip)) {
|
||||
if (await cheapDetector(user.ip)) {
|
||||
logger.info(
|
||||
`${name} / ${user.ip} tried to send chat message with proxy`,
|
||||
);
|
||||
|
|
|
@ -193,14 +193,6 @@ class MailProvider {
|
|||
return reguser.name;
|
||||
}
|
||||
|
||||
static createCode() {
|
||||
const part1 = Math.random().toString(36).substring(2, 15)
|
||||
+ Math.random().toString(36).substring(2, 15);
|
||||
const part2 = Math.random().toString(36).substring(2, 15)
|
||||
+ Math.random().toString(36).substring(2, 15);
|
||||
return `${part1}-${part2}`;
|
||||
}
|
||||
|
||||
static createCode() {
|
||||
return randomUUID();
|
||||
}
|
||||
|
|
|
@ -59,9 +59,6 @@ function evaluateResult(captchaText, userText) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (Math.random() < 0.1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -97,6 +94,7 @@ export async function setCaptchaSolution(
|
|||
* @param text Solution of captcha
|
||||
* @param ip
|
||||
* @param onetime If the captcha is just one time or should be remembered
|
||||
* @param wrongCallback function that gets called when captcha got solved wrong
|
||||
* for this ip
|
||||
* @return 0 if solution right
|
||||
* 1 if timed out
|
||||
|
@ -107,6 +105,7 @@ export async function checkCaptchaSolution(
|
|||
ip,
|
||||
onetime = false,
|
||||
captchaid = null,
|
||||
wrongCallback = null,
|
||||
) {
|
||||
const ipn = getIPv6Subnet(ip);
|
||||
let key = `capt:${ip}`;
|
||||
|
@ -116,6 +115,9 @@ export async function checkCaptchaSolution(
|
|||
const solution = await redis.get(key);
|
||||
if (solution) {
|
||||
if (evaluateResult(solution, text)) {
|
||||
if (Math.random() < 0.1) {
|
||||
return 2;
|
||||
}
|
||||
if (!onetime) {
|
||||
const solvkey = `human:${ipn}`;
|
||||
await redis.set(solvkey, '', {
|
||||
|
@ -128,6 +130,7 @@ export async function checkCaptchaSolution(
|
|||
logger.info(
|
||||
`CAPTCHA ${ip} got captcha wrong (${text} instead of ${solution})`,
|
||||
);
|
||||
wrongCallback(text, solution);
|
||||
return 2;
|
||||
}
|
||||
logger.info(`CAPTCHA ${ip}:${captchaid} timed out`);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import logger from '../../core/logger';
|
||||
import { checkCaptchaSolution } from '../../data/redis/captcha';
|
||||
import { getIPFromRequest } from '../../utils/ip';
|
||||
import chatProvider from '../../core/ChatProvider';
|
||||
|
||||
export default async (req, res) => {
|
||||
const ip = getIPFromRequest(req);
|
||||
|
@ -26,7 +27,21 @@ export default async (req, res) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const ret = await checkCaptchaSolution(text, ip, false, id);
|
||||
const ret = await checkCaptchaSolution(
|
||||
text,
|
||||
ip,
|
||||
false,
|
||||
id,
|
||||
(inpt, solution) => {
|
||||
chatProvider.broadcastChatMessage(
|
||||
'info',
|
||||
// eslint-disable-next-line max-len
|
||||
`Someone got his captcha wrong and entered ${inpt} instead of ${solution}`,
|
||||
chatProvider.enChannelId,
|
||||
chatProvider.infoUserId,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
switch (ret) {
|
||||
case 0:
|
||||
|
|
Loading…
Reference in New Issue
Block a user