├── Model ├── CaptchaResponseResolver.php └── ErrorProcessor.php ├── Observer └── CommentFormObserver.php ├── README.md ├── composer.json ├── etc ├── adminhtml │ └── system.xml ├── config.xml ├── frontend │ ├── di.xml │ └── events.xml └── module.xml ├── registration.php └── view └── frontend └── layout ├── blog_post_view.xml └── hyva_blog_post_view.xml /Model/CaptchaResponseResolver.php: -------------------------------------------------------------------------------- 1 | serializer = $serializer; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | * 37 | * @param RequestInterface|PlainTextRequestInterface $request 38 | * @return string 39 | * @throws InputException 40 | */ 41 | public function resolve(RequestInterface $request): string 42 | { 43 | $content = $request->getContent(); 44 | 45 | if (empty($content)) { 46 | throw new InputException(__('Can not resolve reCAPTCHA response.')); 47 | } 48 | 49 | try { 50 | //$params = $this->serializer->unserialize($content); 51 | $params = []; 52 | parse_str($content, $params); 53 | } catch (\InvalidArgumentException $e) { 54 | throw new InputException(__('Can not resolve reCAPTCHA response.'), $e); 55 | } 56 | 57 | if (empty($params[self::PARAM_RECAPTCHA])) { 58 | throw new InputException(__('Can not resolve reCAPTCHA response.')); 59 | } 60 | 61 | return $params[self::PARAM_RECAPTCHA]; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Model/ErrorProcessor.php: -------------------------------------------------------------------------------- 1 | actionFlag = $actionFlag; 41 | $this->serializer = $serializer; 42 | } 43 | 44 | /** 45 | * Set "no dispatch" flag and error message to Response 46 | * 47 | * @param ResponseInterface $response 48 | * @param string $message 49 | * @return void 50 | */ 51 | public function processError(ResponseInterface $response, string $message): void 52 | { 53 | $this->actionFlag->set('', Action::FLAG_NO_DISPATCH, true); 54 | 55 | $jsonPayload = $this->serializer->serialize( 56 | [ 57 | 'success' => false, 58 | 'message' => $message, 59 | ] 60 | ); 61 | $response->representJson($jsonPayload); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Observer/CommentFormObserver.php: -------------------------------------------------------------------------------- 1 | captchaResponseResolver = $captchaResponseResolver; 74 | $this->validationConfigResolver = $validationConfigResolver; 75 | $this->captchaValidator = $captchaValidator; 76 | $this->isCaptchaEnabled = $isCaptchaEnabled; 77 | $this->logger = $logger; 78 | $this->errorProcessor = $errorProcessor; 79 | } 80 | 81 | /** 82 | * @param Observer $observer 83 | * @return void 84 | * @throws LocalizedException 85 | */ 86 | public function execute(Observer $observer): void 87 | { 88 | $key = 'mfblog_comment'; 89 | if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) { 90 | $controller = $observer->getControllerAction(); 91 | $request = $controller->getRequest(); 92 | $response = $controller->getResponse(); 93 | 94 | $validationConfig = $this->validationConfigResolver->get($key); 95 | 96 | try { 97 | $reCaptchaResponse = $this->captchaResponseResolver->resolve($request); 98 | } catch (InputException $e) { 99 | $this->logger->error($e); 100 | $this->errorProcessor->processError( 101 | $response, 102 | $validationConfig->getValidationFailureMessage() 103 | ); 104 | return; 105 | } 106 | 107 | $validationResult = $this->captchaValidator->isValid($reCaptchaResponse, $validationConfig); 108 | if (false === $validationResult->isValid()) { 109 | $this->errorProcessor->processError( 110 | $response, 111 | $validationConfig->getValidationFailureMessage() 112 | ); 113 | } 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Magento 2 Blog Extension](https://magefan.com/magento2-blog-extension) ReCaptcha 2 | 3 | [![Total Downloads](https://poser.pugx.org/magefan/module-blog-comments-recaptcha/downloads)](https://packagist.org/packages/magefan/module-blog-comments-recaptcha) 4 | [![Latest Stable Version](https://poser.pugx.org/magefan/module-blog-comments-recaptcha/v/stable)](https://packagist.org/packages/magefan/module-blog-comments-recaptcha) 5 | 6 | This Magento 2 Blog ReCaptcha module allows you to enable ReCaptcha in Magefan Blog Comments. 7 | 8 | ## 🇺🇦 Stand with Ukraine! [How can you help?](https://magefan.com/blog/join-our-donations) 9 | 10 | ## Requirements 11 | * Magento Community Edition 2.1.2-2.3.x or Magento Enterprise Edition 2.1.2-2.3.x (use versin 2.0.5) 12 | * Magento Community Edition 2.4.x or Magento Enterprise Edition 2.4.x (use version >= 2.1.2) 13 | * Magefan Blog extension >= 2.9.4.3 14 | 15 | ## Documentation 16 | * [How to enable Blog Comments reCaptcha in Magento 2?](https://magefan.com/magento2-blog-extension/enable-comments-recaptcha) 17 | 18 | ## Demo 19 | 20 | Try out our open demo and if you like our extension **please give us some star on Github ★** 21 | 22 | 23 | 24 | 27 | 30 | 31 | 32 | 41 | 50 | 51 | 52 | 57 | 62 | 63 | 64 |
25 | Storefront Demo 26 | 28 | Admin Panel Demo 29 |
33 | 34 | Magneto 2 Blog Extension Storefront Demo 39 | 40 | 42 | 43 | Magneto 2 Blog Extension Admin Panel Demo 48 | 49 |
53 | 54 | view 55 | 56 | 58 | 59 | view 60 | 61 |
65 | 66 | 67 | ## Installation via the Composer 68 | 69 | ``` 70 | composer require magefan/module-blog-comments-recaptcha 71 | php bin/magento setup:upgrade 72 | php bin/magento setup:di:compile 73 | php bin/magento setup:static-content:deploy 74 | ``` 75 | ## Install via FTP 76 | 1. Download Extension ZIP Archive 77 | 2. Extract files 78 | 3. Copy files from archive into path_to_magento2/app/code/Magefan/BlogCommentsReCaptcha 79 | 4. Run CLI commands: 80 | 81 | ``` 82 | php bin/magento setup:upgrade 83 | php bin/magento setup:di:compile 84 | php bin/magento setup:static-content:deploy 85 | ``` 86 | ## Support 87 | If you have any issues, please [contact us](mailto:support@magefan.com) 88 | then if you still need help, open a bug report in GitHub's 89 | [issue tracker](https://github.com/magefan/module-blog-comments-recaptcha/issues). 90 | 91 | Please do not use Magento Marketplace Reviews or (especially) the Q&A for support. 92 | There isn't a way for us to reply to reviews and the Q&A moderation is very slow. 93 | 94 | ## Need More Features? 95 | Please contact us to get a quote 96 | https://magefan.com/contact 97 | 98 | ## License 99 | The code is licensed under [EULA](https://magefan.com/end-user-license-agreement). 100 | 101 | ## [Magento 2 Extensions](https://magefan.com/magento-2-extensions) by Magefan 102 | 103 | ### [Magento 2 Google Extensions](https://magefan.com/magento-2-extensions/google-extensions) 104 | 105 | * [Magento 2 Google Indexing](https://magefan.com/magento-2-google-indexing-api) 106 | * [Magento 2 Google Analytics 4](https://magefan.com/magento-2-google-analytics-4) 107 | * [Magento 2 Google Tag Manager](https://magefan.com/magento-2-google-tag-manager) 108 | * [Magento 2 Google Shopping Feed](https://magefan.com/magento-2-google-shopping-feed-extension) 109 | * [Magento 2 Google Customer Reviews](https://magefan.com/magento-2-google-customer-reviews) 110 | 111 | ### Magento 2 SEO Extensions 112 | 113 | * [Magento 2 SEO Extension](https://magefan.com/magento-2-seo-extension) 114 | * [Magento 2 Rich Snippets](https://magefan.com/magento-2-rich-snippets) 115 | * [Magento 2 HTML Sitemap](https://magefan.com/magento-2-html-sitemap-extension) 116 | * [Magento 2 XML Sitemap](https://magefan.com/magento-2-xml-sitemap-extension) 117 | * [Magento 2 Facebook Open Graph](https://magefan.com/magento-2-open-graph-extension-og-tags) 118 | * [Magento 2 Twitter Cards](https://magefan.com/magento-2-twitter-cards-extension) 119 | 120 | 121 | ### [Magento 2 Speed Optimization Extensions](https://magefan.com/magento-2-extensions/speed-optimization) 122 | 123 | * [Magento 2 Google Page Speed Optimizer](https://magefan.com/magento-2-google-page-speed-optimizer) 124 | * [Magento 2 Full Page Cache Warmer](https://magefan.com/magento-2-full-page-cache-warmer) 125 | * [Magento 2 Image Lazy Load](https://magefan.com/magento-2-image-lazy-load-extension) 126 | * [Magento 2 WebP Images](https://magefan.com/magento-2-webp-optimized-images) 127 | * [Magento 2 Rocket JavaScript](https://magefan.com/rocket-javascript-deferred-javascript) 128 | 129 | ### [Magento 2 Admin Panel Extensions](https://magefan.com/magento-2-extensions/admin-extensions) 130 | 131 | * [Magento 2 Size Chart Extension](https://magefan.com/magento-2-size-chart) 132 | * [Magento 2 Security Extension](https://magefan.com/magento-2-security-extension) 133 | * [Magento 2 Admin Action Log](https://magefan.com/magento-2-admin-action-log) 134 | * [Magento 2 Order Editor](https://magefan.com/magento-2-edit-order-extension) 135 | * [Magento 2 Better Order Grid](https://magefan.com/magento-2-better-order-grid-extension) 136 | * [Magento 2 Extended Product Grid](https://magefan.com/magento-2-product-grid-inline-editor) 137 | * [Magento 2 Product Tabs](https://magefan.com/magento-2/extensions/product-tabs) 138 | * [Magento 2 Facebook Pixel](https://magefan.com/magento-2-facebook-pixel-extension) 139 | * [Magento 2 Email Attachments](https://magefan.com/magento-2-email-attachments) 140 | * [Magento 2 Admin View](https://magefan.com/magento-2-admin-view-extension) 141 | * [Magento 2 Admin Email Notifications](https://magefan.com/magento-2-admin-email-notifications) 142 | * [Magento 2 Login As Customer](https://magefan.com/login-as-customer-magento-2-extension) 143 | 144 | ### Magento 2 Blog Extensions 145 | 146 | * [Magento 2 Blog](https://magefan.com/magento2-blog-extension) 147 | * [Magento 2 Multi Blog](https://magefan.com/magento-2-multi-blog-extension) 148 | * [Magento 2 Product Widget](https://magefan.com/magento-2-product-widget) 149 | 150 | ### [Magento 2 Marketing Automation Extensions](https://magefan.com/magento-2-extensions/marketing-automation) 151 | 152 | * [Magento 2 Cookie Consent](https://magefan.com/magento-2-cookie-consent) 153 | * [Magento 2 Product Labels](https://magefan.com/magento-2-product-labels) 154 | * [Magento 2 Base Price](https://magefan.com/magento-2-base-price) 155 | * [Magento 2 Dynamic Categories](https://magefan.com/magento-2-dynamic-categories) 156 | * [Magento 2 Dynamic Blocks and Pages Extension](https://magefan.com/magento-2-cms-display-rules-extension) 157 | * [Magento 2 Automatic Related Products](https://magefan.com/magento-2-automatic-related-products) 158 | * [Magento 2 Price History](https://magefan.com/magento-2-price-history) 159 | * [Magento 2 Mautic Integration](https://magefan.com/magento-2-mautic-extension) 160 | * [Magento 2 YouTube Video](https://magefan.com/magento2-youtube-extension) 161 | 162 | ### [Magento 2 Cart Extensions](https://magefan.com/magento-2-extensions/cart-extensions) 163 | 164 | * [Magento 2 Checkout Extension](https://magefan.com/better-magento-2-checkout-extension) 165 | * [Magento 2 Coupon Code](https://magefan.com/magento-2-coupon-code-link) 166 | * [Magento 2 Guest to Customer](https://magefan.com/magento2-convert-guest-to-customer) 167 | 168 | ### [Magento 2 Multi-Language Extensions](https://magefan.com/magento-2-extensions/multi-language-extensions) 169 | 170 | * [Magento 2 Hreflang Tags](https://magefan.com/magento2-alternate-hreflang-extension) 171 | * [Magento 2 Auto Currency Switcher](https://magefan.com/magento-2-currency-switcher-auto-currency-by-country) 172 | * [Magento 2 Auto Language Switcher](https://magefan.com/magento-2-auto-language-switcher) 173 | * [Magento 2 GeoIP Store Switcher](https://magefan.com/magento-2-geoip-switcher-extension) 174 | * [Magento 2 Translation](https://magefan.com/magento-2-translation-extension) 175 | 176 | ### [Developers Tools](https://magefan.com/magento-2-extensions/developer-tools) 177 | 178 | * [Magento 2 Zero Downtime Deployment](https://magefan.com/blog/magento-2-zero-downtime-deployment) 179 | * [Magento 2 Cron Schedule](https://magefan.com/magento-2-cron-schedule) 180 | * [Magento 2 CLI Extension](https://magefan.com/magento2-cli-extension) 181 | * [Magento 2 Conflict Detector](https://magefan.com/magento2-conflict-detector) 182 | 183 | ## [Shopify Apps](https://magefan.com/shopify/apps) by Magefan 184 | 185 | * [Shopify Login As Customer](https://apps.shopify.com/login-as-customer) 186 | * [Shopify Blog](https://apps.shopify.com/magefan-blog) 187 | * [Shopify Size Chart](https://magefan.com/shopify/apps/size-chart) 188 | * [Shopify Google Indexer](https://magefan.com/shopify/apps/google-indexing) 189 | * [Shopify Product Feeds](https://magefan.com/shopify/apps/product-feed) 190 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magefan/module-blog-comments-recaptcha", 3 | "description": "Add recaptcha to Magefan Blog Comments", 4 | "require": { 5 | "magento/module-re-captcha-validation-api" : ">=1.0.0", 6 | "magefan/module-blog" : ">=2.10.12" 7 | }, 8 | "type": "magento2-module", 9 | "version": "2.1.5", 10 | "autoload": { 11 | "files": [ "registration.php" ], 12 | "psr-4": { 13 | "Magefan\\BlogCommentsReCaptcha\\": "" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 |
12 | 13 | 15 | 16 | Magento\ReCaptchaAdminUi\Model\OptionSource\Type 17 | 18 | 19 |
20 |
21 |
22 | -------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | Magefan\BlogCommentsReCaptcha\Model\CaptchaResponseResolver 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /etc/frontend/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 17 | 18 | mfblog_comment 19 | 20 | 21 | 22 | Magento_ReCaptchaFrontendUi/js/reCaptcha 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | mfblog_comment 36 | 37 | 38 | 39 | Magento_ReCaptchaFrontendUi/js/reCaptcha 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /view/frontend/layout/hyva_blog_post_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 12 | 13 | comment_form 14 | 15 | 16 | 18 | 19 | comment_reply_form 20 | 21 | 22 | 23 | 24 | --------------------------------------------------------------------------------