added captcha requirement to create new user

This commit is contained in:
Miodec 2022-09-22 12:56:38 +02:00
parent 34c4c5efd3
commit 6fd6cdf55b
3 changed files with 18 additions and 2 deletions

View file

@ -11,13 +11,22 @@ import { deleteAllApeKeys } from "../../dal/ape-keys";
import { deleteAllPresets } from "../../dal/preset";
import { deleteAll as deleteAllResults } from "../../dal/result";
import { deleteConfig } from "../../dal/config";
import { verify } from "../../utils/captcha";
async function verifyCaptcha(captcha: string): Promise<void> {
if (!(await verify(captcha))) {
throw new MonkeyError(422, "Captcha check failed");
}
}
export async function createNewUser(
req: MonkeyTypes.Request
): Promise<MonkeyResponse> {
const { name } = req.body;
const { name, captcha } = req.body;
const { email, uid } = req.ctx.decodedToken;
await verifyCaptcha(captcha);
if (email.endsWith("@tidal.lol") || email.endsWith("@selfbot.cc")) {
throw new MonkeyError(400, "Invalid domain");
}

View file

@ -102,6 +102,7 @@ router.post(
email: joi.string().email(),
name: usernameValidation,
uid: joi.string(),
captcha: joi.string().required(),
},
}),
asyncHandler(UserController.createNewUser)

View file

@ -9,11 +9,17 @@ export default class Users {
return await this.httpClient.get(BASE_PATH);
}
async create(name: string, email?: string, uid?: string): Ape.EndpointData {
async create(
name: string,
captcha: string,
email?: string,
uid?: string
): Ape.EndpointData {
const payload = {
email,
name,
uid,
captcha,
};
return await this.httpClient.post(`${BASE_PATH}/signup`, { payload });