mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
added captcha requirement to create new user
This commit is contained in:
parent
34c4c5efd3
commit
6fd6cdf55b
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ router.post(
|
|||
email: joi.string().email(),
|
||||
name: usernameValidation,
|
||||
uid: joi.string(),
|
||||
captcha: joi.string().required(),
|
||||
},
|
||||
}),
|
||||
asyncHandler(UserController.createNewUser)
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Reference in a new issue