How nenes25/eicaptcha works
Project Type and Purpose
• Type: An open-source PrestaShop module that injects Google reCAPTCHA (V2/V3) into various customer-facing forms of a PrestaShop 1.7+ shop.
• Purpose: Enhance form security by validating user submissions against Google’s reCAPTCHA service, via PrestaShop hooks and controller overrides.
File Structure
• Top-level Entrypoints
– eicaptcha.php: Module bootstrap, registration of hooks, installation/uninstallation logic.
– index.php stubs (security).
• Overrides
– override/controllers/front/AuthController.php
– override/controllers/front/OrderController.php
– override/modules/contactform/contactform.php
These intercept form-display and form-submit logic in PrestaShop core/controllers and core modules.
• Source (src/)
– Installer.php: module install/upgrade scripts, writes configuration.
– ConfigForm.php: defines back-office configuration form fields (reCAPTCHA keys, options).
– Debugger.php: diagnostic utilities (used in admin debug template).
• Views (views/)
– templates/hook/*.tpl: hook display templates for forms.
– js/css: frontend assets, reCAPTCHA loader scripts.
• Tests
– PHPStan, PHPCS, functional PHP tests, Playwright E2E tests (contact form, registration, newsletter).
• CI/CD
– .github/workflows: PHP linting, release build.
– composer.json: pulls in google/recaptcha package.
README Insights
• Registers on hooks: displayCustomerAccountForm, displayContactForm, displayNewsletterRegistration, custom hooks.
• Supports both V2 (visible) and V3 (invisible) Google reCAPTCHA.
• Relies on composer for recaptcha library.
• Overrides specific controllers rather than replacing core logic entirely.
Main Components & Interactions
a. PrestaShop Core
– Front controllers (AuthController, OrderController)
– Core ContactForm module
– Hook dispatcher
b. eicaptcha Module
– Module bootstrap (eicaptcha.php)
– Installer (writes DB settings, registers hooks)
– ConfigForm (back-office UI)
– Debugger (admin debug display)
– Override classes (intercept form submission, validation)
– Hook display templates (inject reCAPTCHA widget)
– Asset loaders (JS/CSS)
c. External Service
– Google reCAPTCHA API (site & secret keys)
d. Developer Tooling
– Composer (dependency mgr)
– CI workflows (static analysis, tests)
Relationships & Data Flows
• At page-render: PrestaShop core dispatches hook → eicaptcha hook handler injects reCAPTCHA widget via template and JS asset.
• On form submit: Overridden controller method intercepts submission → eicaptcha validation logic calls Google API via composer library → on success, delegates back to core controller; on failure, returns error.
• Back-office: Admin config page reads/writes reCAPTCHA keys via ConfigForm.
• CI: Push → GitHub Actions runs PHP linting, static analysis, functional & E2E tests against a test PrestaShop instance.
Architectural Patterns & Principles
• Extension via Hooks and Overrides (PrestaShop plugin model)
• Separation of Concerns:
– Presentation (templates, JS, CSS)
– Configuration (ConfigForm)
– Business Logic (validation, installer)
– Diagnostics (Debugger)
• Dependency Management via Composer
• Test-Driven Quality (PHPStan, Playwright)