diff --git a/.env.sample b/.env.sample index 46621b7..730e803 100644 --- a/.env.sample +++ b/.env.sample @@ -25,4 +25,4 @@ KEYCLOAK_CLIENT_ID= KEYCLOAK_CLIENT_SECRET= NEXTAUTH_URL= NEXTAUTH_SECRET= -RE_CAPTCHA_SECRET_KEY= \ No newline at end of file +HCAPTCHA_SECRET_KEY= \ No newline at end of file diff --git a/server/lib/mailer/schemas.js b/server/lib/mailer/schemas.js index c37b80c..c2eaa6f 100644 --- a/server/lib/mailer/schemas.js +++ b/server/lib/mailer/schemas.js @@ -6,7 +6,7 @@ const mailSchema = { email: { valid: validEmail, isRequired: true, type: "string" }, message: { isRequired: true, type: "string" }, subject: { isRequired: true, type: "string" }, - reCaptchaToken: { isRequired: true, type: "string" }, + captchaToken: { isRequired: true, type: "string" }, }; module.exports = { diff --git a/server/lib/mailer/service.js b/server/lib/mailer/service.js index dd0e2be..b840f73 100644 --- a/server/lib/mailer/service.js +++ b/server/lib/mailer/service.js @@ -44,15 +44,19 @@ async function sendTemplateMail(templateKey) { return true } -async function checkReCaptcha(reCaptchaToken) { - const response = await fetch(`https://www.google.com/recaptcha/api/siteverify?secret=${process.env.RE_CAPTCHA_SECRET_KEY}&response=${reCaptchaToken}`, { - method: 'POST' +async function checkCaptcha(captchaToken) { + const response = await fetch(`https://api.hcaptcha.com/siteverify`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: `response=${captchaToken}&secret=${process.env.HCAPTCHA_SECRET_KEY}`, }) const json = await response.json() if (!json.success) { - throw new Error('Le reCaptcha est invalide') + throw new Error('Le captcha est invalide') } return json.success @@ -60,9 +64,9 @@ async function checkReCaptcha(reCaptchaToken) { async function sendFormContactMail(payload) { const validatedPayload = validPayload(payload, mailSchema) - const {reCaptchaToken, ...emailData } = validatedPayload + const {captchaToken, ...emailData } = validatedPayload - await checkReCaptcha(reCaptchaToken) + await checkCaptcha(captchaToken) const contactTemplate = templates.contact(emailData)