Story 5.4: reCAPTCHA v3

This commit is contained in:
2026-02-04 21:17:02 +01:00
parent a4e0cb71e9
commit 267b6ff7fa
7 changed files with 153 additions and 30 deletions

View File

@@ -294,7 +294,38 @@ class ContactFormPersistence {
}
}
const RecaptchaService = {
siteKey: null,
init() {
this.siteKey = window.RECAPTCHA_SITE_KEY || null;
},
isAvailable() {
return this.siteKey && typeof grecaptcha !== 'undefined';
},
async getToken(action = 'contact') {
if (!this.isAvailable()) {
console.warn('reCAPTCHA non disponible, envoi sans protection');
return '';
}
return new Promise((resolve) => {
grecaptcha.ready(() => {
grecaptcha.execute(this.siteKey, { action })
.then((token) => resolve(token))
.catch((error) => {
console.error('Erreur reCAPTCHA:', error);
resolve('');
});
});
});
}
};
document.addEventListener('DOMContentLoaded', () => {
RecaptchaService.init();
window.contactFormValidator = new FormValidator('contact-form');
window.contactFormPersistence = new ContactFormPersistence('contact-form');
});