From bd415ccb3e081e666721928c564856259100cd37 Mon Sep 17 00:00:00 2001 From: Gabriel Peleskei Date: Tue, 18 Jul 2023 14:59:11 +0000 Subject: [PATCH 01/15] Basic changes made for smarty and base code --- .gitignore | 5 +- .ide-helper.php | 23 ++ .../Component/Widget/ArticleDetails.php | 12 + Application/Controller/ContactController.php | 21 ++ Application/Controller/DetailsController.php | 23 ++ .../Controller/ForgotPasswordController.php | 21 ++ .../Controller/ImageGeneratorController.php | 102 ++++++ Application/Controller/InviteController.php | 21 ++ .../Controller/NewsletterController.php | 21 ++ .../Controller/PricealarmController.php | 23 ++ .../Core/Captcha.php | 299 ++++++++++-------- Application/Core/Module.php | 62 ++++ Application/Shared/Captcha.php | 21 ++ Application/Shared/Connection.php | 25 ++ Application/Shared/Options.php | 24 ++ .../translations}/de/oecaptcha_de_lang.php | 15 +- .../translations/en/oecaptcha_en_lang.php | 16 + CHANGELOG.md | 8 + .../widget/oecaptchawarticledetails.php | 30 -- application/views/admin/de/module_options.php | 13 - application/views/admin/en/module_options.php | 13 - application/views/blocks/captcha_form.tpl | 3 - .../views/blocks/captcha_form_forgotpwd.tpl | 3 - out/pictures/picture.png => assets/logo.png | Bin composer.json | 19 +- controllers/oecaptchacontact.php | 44 --- controllers/oecaptchadetails.php | 52 --- controllers/oecaptchaforgotpwd.php | 44 --- controllers/oecaptchainvite.php | 49 --- controllers/oecaptchanewsletter.php | 44 --- controllers/oecaptchapricealarm.php | 37 --- controllers/oecaptchasuggest.php | 52 --- core/oecaptchaevents.php | 62 ---- core/utils/verificationimg.php | 103 ------ metadata.php | 130 +++++--- translations/en/oecaptcha_en_lang.php | 17 - .../de/oe_catpcha_admin_de_lang.php | 9 + .../en/oe_captcha_admin_en_lang.php | 9 + .../de/oe_catpcha_admin_de_lang.php | 9 + .../en/oe_captcha_admin_en_lang.php | 9 + .../smarty/block/oe_captcha_form.tpl | 3 + .../admin_twig/smarty/tpl/oe_captcha.tpl | 9 +- views/smarty/block/oe_captcha_form.tpl | 3 + views/smarty/tpl/oe_captcha.tpl | 20 ++ 44 files changed, 760 insertions(+), 768 deletions(-) create mode 100644 .ide-helper.php create mode 100644 Application/Component/Widget/ArticleDetails.php create mode 100644 Application/Controller/ContactController.php create mode 100644 Application/Controller/DetailsController.php create mode 100644 Application/Controller/ForgotPasswordController.php create mode 100644 Application/Controller/ImageGeneratorController.php create mode 100644 Application/Controller/InviteController.php create mode 100644 Application/Controller/NewsletterController.php create mode 100644 Application/Controller/PricealarmController.php rename core/oecaptcha.php => Application/Core/Captcha.php (52%) create mode 100644 Application/Core/Module.php create mode 100644 Application/Shared/Captcha.php create mode 100644 Application/Shared/Connection.php create mode 100644 Application/Shared/Options.php rename {translations => Application/translations}/de/oecaptcha_de_lang.php (76%) create mode 100755 Application/translations/en/oecaptcha_en_lang.php delete mode 100644 application/component/widget/oecaptchawarticledetails.php delete mode 100644 application/views/admin/de/module_options.php delete mode 100644 application/views/admin/en/module_options.php delete mode 100644 application/views/blocks/captcha_form.tpl delete mode 100644 application/views/blocks/captcha_form_forgotpwd.tpl rename out/pictures/picture.png => assets/logo.png (100%) delete mode 100644 controllers/oecaptchacontact.php delete mode 100644 controllers/oecaptchadetails.php delete mode 100644 controllers/oecaptchaforgotpwd.php delete mode 100644 controllers/oecaptchainvite.php delete mode 100644 controllers/oecaptchanewsletter.php delete mode 100644 controllers/oecaptchapricealarm.php delete mode 100644 controllers/oecaptchasuggest.php delete mode 100644 core/oecaptchaevents.php delete mode 100644 core/utils/verificationimg.php delete mode 100755 translations/en/oecaptcha_en_lang.php create mode 100644 views/admin_smarty/de/oe_catpcha_admin_de_lang.php create mode 100644 views/admin_smarty/en/oe_captcha_admin_en_lang.php create mode 100644 views/admin_twig/de/oe_catpcha_admin_de_lang.php create mode 100644 views/admin_twig/en/oe_captcha_admin_en_lang.php create mode 100644 views/admin_twig/smarty/block/oe_captcha_form.tpl rename application/views/tpl/oecaptcha.tpl => views/admin_twig/smarty/tpl/oe_captcha.tpl (70%) create mode 100644 views/smarty/block/oe_captcha_form.tpl create mode 100644 views/smarty/tpl/oe_captcha.tpl diff --git a/.gitignore b/.gitignore index 485dee6..09122f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.idea +.idea/ +.vscode/ +vendor/ +.DS_Store \ No newline at end of file diff --git a/.ide-helper.php b/.ide-helper.php new file mode 100644 index 0000000..b1df0c6 --- /dev/null +++ b/.ide-helper.php @@ -0,0 +1,23 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } +} diff --git a/Application/Controller/DetailsController.php b/Application/Controller/DetailsController.php new file mode 100644 index 0000000..e1543b9 --- /dev/null +++ b/Application/Controller/DetailsController.php @@ -0,0 +1,23 @@ +getCaptcha()->passCaptcha(false)) { + $this->_iPriceAlarmStatus = 2; + + return; + } + + return parent::addme(); + } +} diff --git a/Application/Controller/ForgotPasswordController.php b/Application/Controller/ForgotPasswordController.php new file mode 100644 index 0000000..8dda74f --- /dev/null +++ b/Application/Controller/ForgotPasswordController.php @@ -0,0 +1,21 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::forgotpassword(); + } +} diff --git a/Application/Controller/ImageGeneratorController.php b/Application/Controller/ImageGeneratorController.php new file mode 100644 index 0000000..15edbdb --- /dev/null +++ b/Application/Controller/ImageGeneratorController.php @@ -0,0 +1,102 @@ +emac = Registry::getRequest()->getRequestEscapedParameter('e_mac', null); + if ($this->emac) { + $this->emac = $this->decodeEmac($this->emac); + } + } + + public function render() + { + parent::render(); + + try { + if (!$this->emac) { + throw new StandardException('No e_mac parameter given'); + } + $image = $this->generateVerificationImage(); + if (!$image) { + throw new StandardException('Image generation failed by returning NULL'); + } + header('Content-type: image/png'); + imagepng($image); + imagedestroy($image); + + exit; + } catch (Throwable $e) { + Registry::getLogger()->error(sprintf('%s() | %s', __METHOD__, $e->getMessage()), [$e]); + http_response_code(400); + + exit(1); + } + } + + protected function decodeEmac(string $emac): string + { + $decryptor = new \OxidEsales\Eshop\Core\Decryptor(); + + $key = $this->getOeCaptchaKey(); + + return $decryptor->decrypt($emac, $key); + } + + protected function generateVerificationImage() + { + $image = null; + + switch (true) { + case function_exists('imagecreatetruecolor'): + $image = imagecreatetruecolor($this->imageWidth, $this->imageHeight); + + break; + + case function_exists('imagecreate'): + $image = imagecreate($this->imageWidth, $this->imageHeight); + + break; + + default: + return null; + } + $textX = ($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2; + $textY = ($this->imageHeight - imagefontheight($this->fontSize)) / 2; + + $colors = [ + 'text' => imagecolorallocate($image, 0, 0, 0), + 'shadow1' => imagecolorallocate($image, 200, 200, 200), + 'shadow2' => imagecolorallocate($image, 100, 100, 100), + 'background' => imagecolorallocate($image, 255, 255, 255), + 'border' => imagecolorallocate($image, 0, 0, 0), + ]; + + imagefill($image, 0, 0, $colors['background']); + imagerectangle($image, 0, 0, $this->imageWidth - 1, $this->imageHeight - 1, $colors['border']); + imagestring($image, $this->fontSize, $textX + 1, $textY + 0, $this->emac, $colors['shadow2']); + imagestring($image, $this->fontSize, $textX + 0, $textY + 1, $this->emac, $colors['shadow1']); + imagestring($image, $this->fontSize, $textX, $textY, $this->emac, $colors['text']); + + return $image; + } +} diff --git a/Application/Controller/InviteController.php b/Application/Controller/InviteController.php new file mode 100644 index 0000000..42e3e4d --- /dev/null +++ b/Application/Controller/InviteController.php @@ -0,0 +1,21 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } +} diff --git a/Application/Controller/NewsletterController.php b/Application/Controller/NewsletterController.php new file mode 100644 index 0000000..ddd78bd --- /dev/null +++ b/Application/Controller/NewsletterController.php @@ -0,0 +1,21 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } +} diff --git a/Application/Controller/PricealarmController.php b/Application/Controller/PricealarmController.php new file mode 100644 index 0000000..cc8c455 --- /dev/null +++ b/Application/Controller/PricealarmController.php @@ -0,0 +1,23 @@ +getCaptcha()->passCaptcha(false)) { + $this->_iPriceAlarmStatus = 2; + + return; + } + + return parent::addme(); + } +} diff --git a/core/oecaptcha.php b/Application/Core/Captcha.php similarity index 52% rename from core/oecaptcha.php rename to Application/Core/Captcha.php index 2959fc6..e7b2f27 100644 --- a/core/oecaptcha.php +++ b/Application/Core/Captcha.php @@ -1,47 +1,55 @@ text) { $this->text = ''; - for ($i = 0; $i < $this->macLength; $i++) { + + for ($i = 0; $i < $this->macLength; ++$i) { $this->text .= strtolower($this->macChars[rand(0, strlen($this->macChars) - 1)]); } } @@ -58,38 +67,7 @@ class oeCaptcha extends oxSuperCfg } /** - * Returns text hash - * - * @param string $text User supplie text - * - * @return string - */ - public function getHash($text = null) - { - // inserting captcha record - $time = time() + $this->timeout; - $textHash = $this->getTextHash($text); - - // if session is started - storing captcha info here - $session = $this->getSession(); - if ($session->isSessionStarted()) { - $hash = oxUtilsObject::getInstance()->generateUID(); - $hashArray = $session->getVariable('captchaHashes'); - $hashArray[$hash] = array($textHash => $time); - $session->setVariable('captchaHashes', $hashArray); - } else { - $database = DatabaseProvider::getDb(); - $query = "insert into oecaptcha (oxhash, oxtime) values (" . - $database->quote($textHash) . ", " . $database->quote($time) . ")"; - $database->execute($query); - $hash = $database->getOne('select LAST_INSERT_ID()', false, false); - } - - return $hash; - } - - /** - * Returns given string captcha hash + * Returns given string captcha hash. * * @param string $text string to hash * @@ -105,38 +83,11 @@ class oeCaptcha extends oxSuperCfg return md5('ox' . $text); } - /** - * Returns url to CAPTCHA image generator. - * - * @return string - */ - public function getImageUrl() - { - $config = \OxidEsales\Eshop\Core\Registry::getConfig(); - $url = $config->getCurrentShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac='; - $key = $config->getConfigParam('oecaptchakey'); - - $key = $key ? $key : $config->getConfigParam('sConfigKey'); - - $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); - $url .= $encryptor->encrypt($this->getText(), $key); - - return $url; - } - - /** - * Checks if image could be generated - * - * @return bool - */ - public function isImageVisible() - { - return ((function_exists('imagecreatetruecolor') || function_exists('imagecreate')) && $this->getConfig()->getConfigParam('iUseGDVersion') > 1); - } - /** * Check if captcha is passed. * + * @param mixed $displayError + * * @return bool */ public function passCaptcha($displayError = true) @@ -144,8 +95,8 @@ class oeCaptcha extends oxSuperCfg $return = true; // spam spider prevention - $mac = $this->getConfig()->getRequestParameter('c_mac'); - $macHash = $this->getConfig()->getRequestParameter('c_mach'); + $mac = Registry::getConfig()->getRequestParameter('c_mac'); + $macHash = Registry::getConfig()->getRequestParameter('c_mach'); if (!$this->pass($mac, $macHash)) { $return = false; @@ -153,12 +104,139 @@ class oeCaptcha extends oxSuperCfg if (!$return && $displayError) { // even if there is no exception, use this as a default display method - oxRegistry::get('oxUtilsView')->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE'); + Registry::getUtilsView()->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE'); } return $return; } + /** + * Checks if image could be generated. + * + * @return bool + */ + public function isImageVisible() + { + return (function_exists('imagecreatetruecolor') || function_exists('imagecreate')) && Registry::getConfig()->getConfigParam('iUseGDVersion') > 1; + } + + /** + * Returns url to CAPTCHA image generator. + * + * @return string + */ + public function getImageUrl() + { + $config = Registry::getConfig(); + $key = $this->getOeCaptchaKey(); + $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); + + return $config->getCurrentShopUrl() . sprintf('?cl=ith_basic_captcha_generator&e_mac=%s&shp=%d', $encryptor->encrypt($this->getText(), $key), $config->getShopId()); + } + + /** + * Returns text hash. + * + * @param string $text User supplie text + * + * @return string + */ + public function getHash($text = null) + { + // inserting captcha record + $time = time() + $this->timeout; + $textHash = $this->getTextHash($text); + + // if session is started - storing captcha info here + $session = Registry::getSession(); + if ($session->isSessionStarted()) { + $hash = UtilsObject::getInstance()->generateUID(); + $hashArray = $session->getVariable('captchaHashes'); + $hashArray[$hash] = [$textHash => $time]; + $session->setVariable('captchaHashes', $hashArray); + } else { + $q = $this->getQueryBuilder(); + $q->insert('oecaptcha') + ->values( + [ + 'oxhash' => '?', + 'oxtime' => '?', + ] + )->setParameter(0, $textHash)->setParameter(1, $time); + $q->execute(); + $hash = $q->getConnection()->lastInsertId(); + } + + return $hash; + } + + /** + * Checks for DB captcha hash validity. + * + * @param int $macHash hash key + * @param string $hash captcha hash + * @param int $time check time + * + * @return bool + */ + protected function passFromDb($macHash, $hash, $time) + { + $q = $this->getQueryBuilder(); + $q->select('1') + ->from('oecaptcha') + ->where('oxid = :macHash') + ->andWhere('oxhash = :hash') + ->setParameter('macHash', $macHash) + ->setParameter('hash', $hash); + $pass = (bool) $q->execute()->fetchOne(); + if ($pass) { + // cleanup + $q = $this->getQueryBuilder() + ->delete('oecaptcha') + ->where('oxid = :macHash') + ->andWhere('oxhash = :hash') + ->setParameter('macHash', $macHash) + ->setParameter('hash', $hash); + $q->execute(); + } + + // garbage cleanup + $q = $this->getQueryBuilder() + ->delete('oecaptcha') + ->where('oxtime < :time') + ->setParameter('time', $time); + $q->execute(); + + return $pass; + } + + /** + * Checks for session captcha hash validity. + * + * @param string $macHash hash key + * @param string $hash captcha hash + * @param int $time check time + * + * @return bool + */ + protected function passFromSession($macHash, $hash, $time) + { + $pass = null; + $session = Registry::getSession(); + + if ($hashArray = $session->getVariable('captchaHashes')) { + $pass = (isset($hashArray[$macHash][$hash]) && $hashArray[$macHash][$hash] >= $time) ? true : false; + unset($hashArray[$macHash]); + if (!empty($hashArray)) { + $session->setVariable('captchaHashes', $hashArray); + } else { + $session->deleteVariable('captchaHashes'); + } + } + + return $pass; + } + /** * Verifies captcha input vs supplied hash. Returns true on success. * @@ -174,67 +252,10 @@ class oeCaptcha extends oxSuperCfg $pass = $this->passFromSession($macHash, $hash, $time); // if captcha info was NOT stored in session - if ($pass === null) { + if (null === $pass) { $pass = $this->passFromDb((int) $macHash, $hash, $time); } return (bool) $pass; } - - /** - * Checks for session captcha hash validity - * - * @param string $macHash hash key - * @param string $hash captcha hash - * @param int $time check time - * - * @return bool - */ - protected function passFromSession($macHash, $hash, $time) - { - $pass = null; - $session = $this->getSession(); - - if (($hashArray = $session->getVariable('captchaHashes'))) { - $pass = (isset($hashArray[$macHash][$hash]) && $hashArray[$macHash][$hash] >= $time) ? true : false; - unset($hashArray[$macHash]); - if (!empty($hashArray)) { - $session->setVariable('captchaHashes', $hashArray); - } else { - $session->deleteVariable('captchaHashes'); - } - } - - return $pass; - } - - /** - * Checks for DB captcha hash validity - * - * @param int $macHash hash key - * @param string $hash captcha hash - * @param int $time check time - * - * @return bool - */ - protected function passFromDb($macHash, $hash, $time) - { - $database = DatabaseProvider::getDb(); - $where = "where oxid = " . $database->quote($macHash) . " and oxhash = " . $database->quote($hash); - $query = "select 1 from oecaptcha " . $where; - $pass = (bool) $database->getOne($query, false, false); - - if ($pass) { - // cleanup - $query = "delete from oecaptcha " . $where; - $database->execute($query); - } - - // garbage cleanup - $query = "delete from oecaptcha where oxtime < $time"; - $database->execute($query); - - return $pass; - } - } diff --git a/Application/Core/Module.php b/Application/Core/Module.php new file mode 100644 index 0000000..7e7edbd --- /dev/null +++ b/Application/Core/Module.php @@ -0,0 +1,62 @@ +activate(); + } + + public static function onDeactivate(): void + { + static::getInstance()->deactivate(); + } + + public function createTable(): void + { + $this->getDb()->executeStatement(' + CREATE TABLE IF NOT EXISTS `oecaptcha` (' . + "`OXID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Captcha id'," . + "`OXHASH` char(32) NOT NULL default '' COMMENT 'Hash'," . + "`OXTIME` int(11) NOT NULL COMMENT 'Validation time'," . + "`OXTIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT 'Timestamp'," . + 'PRIMARY KEY (`OXID`), ' . + 'KEY `OXID` (`OXID`,`OXHASH`), ' . + 'KEY `OXTIME` (`OXTIME`) ' . + ") ENGINE=MEMORY AUTO_INCREMENT=1 COMMENT 'If session is not available, this is where captcha information is stored'; + "); + } + + public function dropTable(): void + { + $this->getDb()->executeStatement('DROP TABLE IF EXISTS `oecaptcha`;'); + } + + public function activate(): void + { + $this->createTable(); + } + + public function deactivate(): void + { + $this->dropTable(); + } +} diff --git a/Application/Shared/Captcha.php b/Application/Shared/Captcha.php new file mode 100644 index 0000000..a41ebe2 --- /dev/null +++ b/Application/Shared/Captcha.php @@ -0,0 +1,21 @@ +captcha) { + $this->captcha = CaptchaCore::getInstance(); + } + + return $this->captcha; + } +} diff --git a/Application/Shared/Connection.php b/Application/Shared/Connection.php new file mode 100644 index 0000000..625f1b3 --- /dev/null +++ b/Application/Shared/Connection.php @@ -0,0 +1,25 @@ +getContainer(); + + return $container->get(QueryBuilderFactoryInterface::class)->create(); + } + + public function getDb(): \Doctrine\DBAL\Connection + { + return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get(); + } +} diff --git a/Application/Shared/Options.php b/Application/Shared/Options.php new file mode 100644 index 0000000..9359bab --- /dev/null +++ b/Application/Shared/Options.php @@ -0,0 +1,24 @@ +getContainer()->get(ModuleSettingServiceInterface::class); + $key = $bridge->getString('oeCaptchaKey', 'oecaptcha')->toString(); + if (!trim($key)) { + return static::ENCRYPT_KEY; + } + + return $key; + } +} diff --git a/translations/de/oecaptcha_de_lang.php b/Application/translations/de/oecaptcha_de_lang.php similarity index 76% rename from translations/de/oecaptcha_de_lang.php rename to Application/translations/de/oecaptcha_de_lang.php index 0effcb4..cce27b9 100755 --- a/translations/de/oecaptcha_de_lang.php +++ b/Application/translations/de/oecaptcha_de_lang.php @@ -1,17 +1,16 @@ 'UTF-8', - 'MESSAGE_WRONG_VERIFICATION_CODE' => 'Der Prüfcode, den Sie eingegeben haben, ist nicht korrekt. Bitte versuchen Sie es erneut!' -); + 'MESSAGE_WRONG_VERIFICATION_CODE' => 'Der Prüfcode, den Sie eingegeben haben, ist nicht korrekt. Bitte versuchen Sie es erneut!', +]; diff --git a/Application/translations/en/oecaptcha_en_lang.php b/Application/translations/en/oecaptcha_en_lang.php new file mode 100755 index 0000000..0af4aec --- /dev/null +++ b/Application/translations/en/oecaptcha_en_lang.php @@ -0,0 +1,16 @@ + 'UTF-8', + 'MESSAGE_WRONG_VERIFICATION_CODE' => 'The verification code you entered is not correct. Please try again.', +]; diff --git a/CHANGELOG.md b/CHANGELOG.md index ef2c2b6..f532d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Security +## [7.0.0] - 18 Jul 2023 +### Changed +- PHP 8.0 compatibility +- OXID 7.0 compatibility +- Twig & Smarty Support +- Major version bump to 7.0.0 to match OXID 7.0 compatibility +### Removed +- Suggest dropped out ## [2.0.4] - 22 Oct 2021 diff --git a/application/component/widget/oecaptchawarticledetails.php b/application/component/widget/oecaptchawarticledetails.php deleted file mode 100644 index 773159e..0000000 --- a/application/component/widget/oecaptchawarticledetails.php +++ /dev/null @@ -1,30 +0,0 @@ -captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - return $this->captcha; - } -} diff --git a/application/views/admin/de/module_options.php b/application/views/admin/de/module_options.php deleted file mode 100644 index 8440e95..0000000 --- a/application/views/admin/de/module_options.php +++ /dev/null @@ -1,13 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'Allgemein', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -); diff --git a/application/views/admin/en/module_options.php b/application/views/admin/en/module_options.php deleted file mode 100644 index b9b8e88..0000000 --- a/application/views/admin/en/module_options.php +++ /dev/null @@ -1,13 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'General', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -); diff --git a/application/views/blocks/captcha_form.tpl b/application/views/blocks/captcha_form.tpl deleted file mode 100644 index 531645c..0000000 --- a/application/views/blocks/captcha_form.tpl +++ /dev/null @@ -1,3 +0,0 @@ -[{$smarty.block.parent}] - -[{include file="oecaptcha.tpl" labelCssClass="col-lg-2" inputCssClass="col-lg-10"}] diff --git a/application/views/blocks/captcha_form_forgotpwd.tpl b/application/views/blocks/captcha_form_forgotpwd.tpl deleted file mode 100644 index 5171b71..0000000 --- a/application/views/blocks/captcha_form_forgotpwd.tpl +++ /dev/null @@ -1,3 +0,0 @@ -[{$smarty.block.parent}] - -[{include file="oecaptcha.tpl" labelCssClass="col-md-3" inputCssClass="col-md-9"}] diff --git a/out/pictures/picture.png b/assets/logo.png similarity index 100% rename from out/pictures/picture.png rename to assets/logo.png diff --git a/composer.json b/composer.json index b24f871..0c45897 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,13 @@ "name": "oxid-projects/captcha-module", "description": "This is Captcha module for OXID eShop.", "type": "oxideshop-module", - "keywords": ["oxid", "modules", "eShop", "captcha"], + "version": "7.0.0", + "keywords": [ + "oxid", + "modules", + "eShop", + "captcha" + ], "homepage": "https://www.oxid-esales.com/en/home.html", "license": [ "GPL-3.0", @@ -12,5 +18,14 @@ "oxideshop": { "target-directory": "oe/captcha" } + }, + "require": { + "oxid-esales/oxideshop-ce": "^7.0", + "ext-gd": "*" + }, + "autoload": { + "psr-4": { + "OxidProfessionalServices\\Captcha\\": "./" + } } -} +} \ No newline at end of file diff --git a/controllers/oecaptchacontact.php b/controllers/oecaptchacontact.php deleted file mode 100644 index b9af7d9..0000000 --- a/controllers/oecaptchacontact.php +++ /dev/null @@ -1,44 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - - return $this->captcha; - } - -} diff --git a/controllers/oecaptchadetails.php b/controllers/oecaptchadetails.php deleted file mode 100644 index a2056e3..0000000 --- a/controllers/oecaptchadetails.php +++ /dev/null @@ -1,52 +0,0 @@ -getCaptcha()->passCaptcha(false)) { - $this->_iPriceAlarmStatus = 2; - return; - } - - return parent::addme(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - return $this->captcha; - } -} diff --git a/controllers/oecaptchaforgotpwd.php b/controllers/oecaptchaforgotpwd.php deleted file mode 100644 index 7158f89..0000000 --- a/controllers/oecaptchaforgotpwd.php +++ /dev/null @@ -1,44 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::forgotpassword(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - - return $this->captcha; - } - -} diff --git a/controllers/oecaptchainvite.php b/controllers/oecaptchainvite.php deleted file mode 100644 index f849ec9..0000000 --- a/controllers/oecaptchainvite.php +++ /dev/null @@ -1,49 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - - return $this->captcha; - } - -} diff --git a/controllers/oecaptchanewsletter.php b/controllers/oecaptchanewsletter.php deleted file mode 100644 index caf7000..0000000 --- a/controllers/oecaptchanewsletter.php +++ /dev/null @@ -1,44 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - - return $this->captcha; - } - -} diff --git a/controllers/oecaptchapricealarm.php b/controllers/oecaptchapricealarm.php deleted file mode 100644 index ddea7eb..0000000 --- a/controllers/oecaptchapricealarm.php +++ /dev/null @@ -1,37 +0,0 @@ - pricealarm. - */ -class oeCaptchaPricealarm extends oeCaptchaPricealarm_parent -{ - /** - * Validates email - * address. If email is wrong - returns false and exits. If email - * address is OK - creates prcealarm object and saves it - * (oxpricealarm::save()). Sends pricealarm notification mail - * to shop owner. - * - * @return bool false on error - */ - public function addme() - { - //control captcha - $captcha = oxNew('oeCaptcha'); - if (!$captcha->passCaptcha(false)) { - $this->_iPriceAlarmStatus = 2; - - return; - } - - return parent::addme(); - } -} diff --git a/controllers/oecaptchasuggest.php b/controllers/oecaptchasuggest.php deleted file mode 100644 index 73d1db8..0000000 --- a/controllers/oecaptchasuggest.php +++ /dev/null @@ -1,52 +0,0 @@ -editval, error - * - * @return null - */ - public function send() - { - // spam spider prevension - if (!$this->getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } - - /** - * Template variable getter. Returns object of handling CAPTCHA image - * - * @return object - */ - public function getCaptcha() - { - if ($this->captcha === null) { - $this->captcha = oxNew('oeCaptcha'); - } - - return $this->captcha; - } -} diff --git a/core/oecaptchaevents.php b/core/oecaptchaevents.php deleted file mode 100644 index f647ee6..0000000 --- a/core/oecaptchaevents.php +++ /dev/null @@ -1,62 +0,0 @@ -execute($query); - } - - /** - * Remove table oecaptcha. - * NOTE: table oecaptcha contains temporary data if any and can be - * removed without side effects on module deactivation - */ - public static function removeCaptchaTable() - { - $query = "DROP TABLE IF EXISTS `oecaptcha`"; - - DatabaseProvider::getDb()->execute($query); - } - - /** - * Execute action on activate event - * - * @return null - */ - public static function onActivate() - { - self::addCaptchaTable(); - } - - /** - * Execute action on deactivate event - * - * @return null - */ - public static function onDeactivate() - { - self::removeCaptchaTable(); - } -} diff --git a/core/utils/verificationimg.php b/core/utils/verificationimg.php deleted file mode 100644 index 769931e..0000000 --- a/core/utils/verificationimg.php +++ /dev/null @@ -1,103 +0,0 @@ -getConfigParam('oecaptchakey'); - if (empty($key)) { - $key = getOxConfKey(); - } - - return $decryptor->decrypt($value, $key); - } -} - -if (!function_exists('getOxConfKey')) { - - /** - * Get default config key. - * - * @return string - */ - function getOxConfKey() - { - $config = oxRegistry::getConfig(); - $configKey = $config->getConfigParam('sConfigKey') ?: \OxidEsales\Eshop\Core\Config::DEFAULT_CONFIG_KEY; - return $configKey; - } - -} - -$mac = strRem($emac); -generateVerificationImg($mac); diff --git a/metadata.php b/metadata.php index b8e7bd9..6b21e8c 100755 --- a/metadata.php +++ b/metadata.php @@ -1,6 +1,9 @@ 'oecaptcha', - 'title' => array( +$aModule = [ + 'id' => Module::ID, + 'title' => [ 'de' => 'Simple Captcha', 'en' => 'Simple Captcha', - ), - 'description' => array( + ], + 'description' => [ 'de' => 'OXID eSales Simple Captcha Module', 'en' => 'OXID eSales Simple Captcha Module', - ), - 'thumbnail' => 'out/pictures/picture.png', - 'version' => '2.0.4', - 'author' => 'OXID eSales AG', - 'url' => 'http://www.oxid-esales.com/', - 'email' => '', - 'extend' => array('details' => 'oe/captcha/controllers/oecaptchadetails', - 'contact' => 'oe/captcha/controllers/oecaptchacontact', - 'forgotpwd' => 'oe/captcha/controllers/oecaptchaforgotpwd', - 'invite' => 'oe/captcha/controllers/oecaptchainvite', - 'newsletter' => 'oe/captcha/controllers/oecaptchanewsletter', - 'pricealarm' => 'oe/captcha/controllers/oecaptchapricealarm', - 'suggest' => 'oe/captcha/controllers/oecaptchasuggest', - 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails'), - 'files' => array( - 'oecaptcha' => 'oe/captcha/core/oecaptcha.php', - 'oecaptchaEvents' => 'oe/captcha/core/oecaptchaevents.php', - ), - 'templates' => array( - 'oecaptcha.tpl' => 'oe/captcha/application/views/tpl/oecaptcha.tpl', - ), - 'blocks' => array( - array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/privatesales/invite.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), - ), - 'settings' => array( - array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), - ), - 'events' => array( - 'onActivate' => 'oecaptchaevents::onActivate', - 'onDeactivate' => 'oecaptchaevents::onDeactivate' - ), -); + ], + 'thumbnail' => 'logo.png', + 'version' => Module::VERSION, + 'author' => 'OXID eSales AG', + 'url' => 'https://www.oxid-esales.com/', + 'email' => '', + 'controllers' => [ + 'ith_basic_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class, + ], + 'extend' => [ + OxidEsales\Eshop\Application\Controller\ArticleDetailsController::class => OxidProfessionalServices\Captcha\Application\Controller\DetailsController::class, + OxidEsales\Eshop\Application\Controller\ContactController::class => OxidProfessionalServices\Captcha\Application\Controller\ContactController::class, + OxidEsales\Eshop\Application\Controller\ForgotPasswordController::class => OxidProfessionalServices\Captcha\Application\Controller\ForgotPasswordController::class, + OxidEsales\Eshop\Application\Controller\InviteController::class => OxidProfessionalServices\Captcha\Application\Controller\InviteController::class, + OxidEsales\Eshop\Application\Controller\NewsletterController::class => OxidProfessionalServices\Captcha\Application\Controller\NewsletterController::class, + OxidEsales\Eshop\Application\Controller\PriceAlarmController::class => OxidProfessionalServices\Captcha\Application\Controller\PricealarmController::class, + OxidEsales\Eshop\Application\Component\Widget\ArticleDetails::class => OxidProfessionalServices\Captcha\Application\Component\Widget\ArticleDetails::class, + ], + 'templates' => [ + 'oe_captcha.tpl' => 'views/smarty/tpl/oe_captcha.tpl', + ], + 'blocks' => [ + [ + 'template' => 'form/contact.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/newsletter.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/privatesales/invite.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/pricealarm.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/suggest.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/forgotpwd_email.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + ], + 'settings' => [ + [ + 'group' => 'main', + 'name' => 'oecaptchakey', + 'type' => 'str', + 'value' => '', + ], + ], + 'events' => [ + 'onActivate' => Module::class . '::onActivate', + 'onDeactivate' => Module::class . '::onDeactivate', + ], +]; diff --git a/translations/en/oecaptcha_en_lang.php b/translations/en/oecaptcha_en_lang.php deleted file mode 100755 index 45abef1..0000000 --- a/translations/en/oecaptcha_en_lang.php +++ /dev/null @@ -1,17 +0,0 @@ - 'UTF-8', - 'MESSAGE_WRONG_VERIFICATION_CODE' => "The verification code you entered is not correct. Please try again." -); diff --git a/views/admin_smarty/de/oe_catpcha_admin_de_lang.php b/views/admin_smarty/de/oe_catpcha_admin_de_lang.php new file mode 100644 index 0000000..5b16ac8 --- /dev/null +++ b/views/admin_smarty/de/oe_catpcha_admin_de_lang.php @@ -0,0 +1,9 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'Allgemein', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +]; diff --git a/views/admin_smarty/en/oe_captcha_admin_en_lang.php b/views/admin_smarty/en/oe_captcha_admin_en_lang.php new file mode 100644 index 0000000..2ecd391 --- /dev/null +++ b/views/admin_smarty/en/oe_captcha_admin_en_lang.php @@ -0,0 +1,9 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'General', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +]; diff --git a/views/admin_twig/de/oe_catpcha_admin_de_lang.php b/views/admin_twig/de/oe_catpcha_admin_de_lang.php new file mode 100644 index 0000000..5b16ac8 --- /dev/null +++ b/views/admin_twig/de/oe_catpcha_admin_de_lang.php @@ -0,0 +1,9 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'Allgemein', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +]; diff --git a/views/admin_twig/en/oe_captcha_admin_en_lang.php b/views/admin_twig/en/oe_captcha_admin_en_lang.php new file mode 100644 index 0000000..2ecd391 --- /dev/null +++ b/views/admin_twig/en/oe_captcha_admin_en_lang.php @@ -0,0 +1,9 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'General', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +]; diff --git a/views/admin_twig/smarty/block/oe_captcha_form.tpl b/views/admin_twig/smarty/block/oe_captcha_form.tpl new file mode 100644 index 0000000..4c9afc7 --- /dev/null +++ b/views/admin_twig/smarty/block/oe_captcha_form.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oe_captcha.tpl"}] \ No newline at end of file diff --git a/application/views/tpl/oecaptcha.tpl b/views/admin_twig/smarty/tpl/oe_captcha.tpl similarity index 70% rename from application/views/tpl/oecaptcha.tpl rename to views/admin_twig/smarty/tpl/oe_captcha.tpl index be78fb2..4c8b439 100644 --- a/application/views/tpl/oecaptcha.tpl +++ b/views/admin_twig/smarty/tpl/oe_captcha.tpl @@ -1,10 +1,10 @@ [{assign var="oCaptcha" value=$oView->getCaptcha()}] - +
- + -
+
[{if $oCaptcha->isImageVisible()}] @@ -13,7 +13,8 @@ [{$oCaptcha->getText()}] [{/if}] - +
\ No newline at end of file diff --git a/views/smarty/block/oe_captcha_form.tpl b/views/smarty/block/oe_captcha_form.tpl new file mode 100644 index 0000000..4c9afc7 --- /dev/null +++ b/views/smarty/block/oe_captcha_form.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oe_captcha.tpl"}] \ No newline at end of file diff --git a/views/smarty/tpl/oe_captcha.tpl b/views/smarty/tpl/oe_captcha.tpl new file mode 100644 index 0000000..4c8b439 --- /dev/null +++ b/views/smarty/tpl/oe_captcha.tpl @@ -0,0 +1,20 @@ +[{assign var="oCaptcha" value=$oView->getCaptcha()}] + + +
+ + +
+
+ + [{if $oCaptcha->isImageVisible()}] + + [{else}] + [{$oCaptcha->getText()}] + [{/if}] + + +
+
+
\ No newline at end of file From e802847f06ece037f3f2626afd8a392d9cc97483 Mon Sep 17 00:00:00 2001 From: Gabriel Peleskei Date: Wed, 19 Jul 2023 09:05:40 +0000 Subject: [PATCH 02/15] twig support tested manually --- .../Controller/ImageGeneratorController.php | 10 ++--- Application/Core/Captcha.php | 6 +-- Application/Shared/Captcha.php | 8 +--- Application/Shared/Options.php | 7 ++- .../translations/de/oecaptcha_de_lang.php | 1 + .../translations/en/oecaptcha_en_lang.php | 2 + .../de/oe_captcha_admin_de_lang.php | 0 .../en/oe_captcha_admin_en_lang.php | 0 .../de/oe_captcha_admin_de_lang.php | 0 .../en/oe_captcha_admin_en_lang.php | 0 README.md | 44 ++++++++++++++----- metadata.php | 19 +------- .../smarty/block/oe_captcha_form.tpl | 3 -- .../tpl => smarty/tpl/include}/oe_captcha.tpl | 2 +- views/smarty/tpl/oe_captcha.tpl | 20 --------- .../themes/default/form/contact.html.twig | 6 +++ .../themes/default/form/pricealarm.html.twig | 6 +++ .../form/privatesales/invite.html.twig | 6 +++ views/twig/oe_captcha.html.twig | 26 +++++++++++ 19 files changed, 97 insertions(+), 69 deletions(-) rename views/admin_smarty/de/oe_catpcha_admin_de_lang.php => Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php (100%) rename {views => Application/views}/admin_smarty/en/oe_captcha_admin_en_lang.php (100%) rename views/admin_twig/de/oe_catpcha_admin_de_lang.php => Application/views/admin_twig/de/oe_captcha_admin_de_lang.php (100%) rename {views => Application/views}/admin_twig/en/oe_captcha_admin_en_lang.php (100%) delete mode 100644 views/admin_twig/smarty/block/oe_captcha_form.tpl rename views/{admin_twig/smarty/tpl => smarty/tpl/include}/oe_captcha.tpl (92%) delete mode 100644 views/smarty/tpl/oe_captcha.tpl create mode 100644 views/twig/extensions/themes/default/form/contact.html.twig create mode 100644 views/twig/extensions/themes/default/form/pricealarm.html.twig create mode 100644 views/twig/extensions/themes/default/form/privatesales/invite.html.twig create mode 100644 views/twig/oe_captcha.html.twig diff --git a/Application/Controller/ImageGeneratorController.php b/Application/Controller/ImageGeneratorController.php index 15edbdb..e53422a 100644 --- a/Application/Controller/ImageGeneratorController.php +++ b/Application/Controller/ImageGeneratorController.php @@ -15,8 +15,8 @@ class ImageGeneratorController extends FrontendController use Options; protected $emac; - protected $imageHeight = 18; - protected $imageWidth = 80; + protected int $imageHeight = 18; + protected int $imageWidth = 80; protected $fontSize = 14; public function init() @@ -80,8 +80,8 @@ class ImageGeneratorController extends FrontendController default: return null; } - $textX = ($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2; - $textY = ($this->imageHeight - imagefontheight($this->fontSize)) / 2; + $textX = (int)ceil(($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2); + $textY = (int)ceil(($this->imageHeight - imagefontheight($this->fontSize)) / 2) - 1; $colors = [ 'text' => imagecolorallocate($image, 0, 0, 0), @@ -92,7 +92,7 @@ class ImageGeneratorController extends FrontendController ]; imagefill($image, 0, 0, $colors['background']); - imagerectangle($image, 0, 0, $this->imageWidth - 1, $this->imageHeight - 1, $colors['border']); + imagerectangle($image, 0, 0, $this->imageWidth - 2, $this->imageHeight - 2, $colors['border']); imagestring($image, $this->fontSize, $textX + 1, $textY + 0, $this->emac, $colors['shadow2']); imagestring($image, $this->fontSize, $textX + 0, $textY + 1, $this->emac, $colors['shadow1']); imagestring($image, $this->fontSize, $textX, $textY, $this->emac, $colors['text']); diff --git a/Application/Core/Captcha.php b/Application/Core/Captcha.php index e7b2f27..cba5d81 100644 --- a/Application/Core/Captcha.php +++ b/Application/Core/Captcha.php @@ -95,8 +95,8 @@ class Captcha $return = true; // spam spider prevention - $mac = Registry::getConfig()->getRequestParameter('c_mac'); - $macHash = Registry::getConfig()->getRequestParameter('c_mach'); + $mac = Registry::getRequest()->getRequestParameter('c_mac'); + $macHash = Registry::getRequest()->getRequestParameter('c_mach'); if (!$this->pass($mac, $macHash)) { $return = false; @@ -131,7 +131,7 @@ class Captcha $key = $this->getOeCaptchaKey(); $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); - return $config->getCurrentShopUrl() . sprintf('?cl=ith_basic_captcha_generator&e_mac=%s&shp=%d', $encryptor->encrypt($this->getText(), $key), $config->getShopId()); + return $config->getCurrentShopUrl() . sprintf('?cl=oe_captcha_generator&e_mac=%s&shp=%d', $encryptor->encrypt($this->getText(), $key), $config->getShopId()); } /** diff --git a/Application/Shared/Captcha.php b/Application/Shared/Captcha.php index a41ebe2..0ba062e 100644 --- a/Application/Shared/Captcha.php +++ b/Application/Shared/Captcha.php @@ -8,14 +8,10 @@ use OxidProfessionalServices\Captcha\Application\Core\Captcha as CaptchaCore; trait Captcha { - protected ?CaptchaCore $captcha; + protected ?CaptchaCore $oeCaptcha; public function getCaptcha(): CaptchaCore { - if (!$this->captcha) { - $this->captcha = CaptchaCore::getInstance(); - } - - return $this->captcha; + return $this->oeCaptcha ??= CaptchaCore::getInstance(); } } diff --git a/Application/Shared/Options.php b/Application/Shared/Options.php index 9359bab..1391e1e 100644 --- a/Application/Shared/Options.php +++ b/Application/Shared/Options.php @@ -6,17 +6,16 @@ namespace OxidProfessionalServices\Captcha\Application\Shared; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; +use OxidProfessionalServices\Captcha\Application\Core\Captcha; trait Options { - public const ENCRYPT_KEY = 'fq45QS09_fqyx09239QQ'; - public function getOeCaptchaKey(): string { $bridge = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class); - $key = $bridge->getString('oeCaptchaKey', 'oecaptcha')->toString(); + $key = $bridge->getString('oecaptchakey', 'oecaptcha')->toString(); if (!trim($key)) { - return static::ENCRYPT_KEY; + return Captcha::ENCRYPT_KEY; } return $key; diff --git a/Application/translations/de/oecaptcha_de_lang.php b/Application/translations/de/oecaptcha_de_lang.php index cce27b9..02977fe 100755 --- a/Application/translations/de/oecaptcha_de_lang.php +++ b/Application/translations/de/oecaptcha_de_lang.php @@ -13,4 +13,5 @@ $sLangName = 'Deutsch'; $aLang = [ 'charset' => 'UTF-8', 'MESSAGE_WRONG_VERIFICATION_CODE' => 'Der Prüfcode, den Sie eingegeben haben, ist nicht korrekt. Bitte versuchen Sie es erneut!', + 'OECAPTCHA_PLACEHOLDER' => 'Enter verification code here', ]; diff --git a/Application/translations/en/oecaptcha_en_lang.php b/Application/translations/en/oecaptcha_en_lang.php index 0af4aec..0c84406 100755 --- a/Application/translations/en/oecaptcha_en_lang.php +++ b/Application/translations/en/oecaptcha_en_lang.php @@ -13,4 +13,6 @@ $sLangName = 'English'; $aLang = [ 'charset' => 'UTF-8', 'MESSAGE_WRONG_VERIFICATION_CODE' => 'The verification code you entered is not correct. Please try again.', + 'OECAPTCHA_PLACEHOLDER' => 'Prüfcode hier eingeben', + ]; diff --git a/views/admin_smarty/de/oe_catpcha_admin_de_lang.php b/Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php similarity index 100% rename from views/admin_smarty/de/oe_catpcha_admin_de_lang.php rename to Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php diff --git a/views/admin_smarty/en/oe_captcha_admin_en_lang.php b/Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php similarity index 100% rename from views/admin_smarty/en/oe_captcha_admin_en_lang.php rename to Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php diff --git a/views/admin_twig/de/oe_catpcha_admin_de_lang.php b/Application/views/admin_twig/de/oe_captcha_admin_de_lang.php similarity index 100% rename from views/admin_twig/de/oe_catpcha_admin_de_lang.php rename to Application/views/admin_twig/de/oe_captcha_admin_de_lang.php diff --git a/views/admin_twig/en/oe_captcha_admin_en_lang.php b/Application/views/admin_twig/en/oe_captcha_admin_en_lang.php similarity index 100% rename from views/admin_twig/en/oe_captcha_admin_en_lang.php rename to Application/views/admin_twig/en/oe_captcha_admin_en_lang.php diff --git a/README.md b/README.md index dd83b41..98bfc8c 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ It is used to ensure that only a user who can read the distorted characters and can submit the following forms: - contact - invite - - pricealarm - - suggest + - pricealarm (not bound in twig) The captcha module then validates the submitted value against the expected one and then decides whether to process the request (e.g. send contact mail to shop administrator) or refuse and show an error message instead. @@ -24,29 +23,54 @@ Please proceed with one of the following ways to install the module: In order to install the module via composer, run the following commands in commandline of your shop base directory (where the shop's composer.json file resides). -``` +```bash composer require oxid-projects/captcha-module ``` ### Module installation via repository cloning Clone the module to your OXID eShop **modules/oe/** directory: -``` +```bash git clone https://github.com/OXIDprojects/captcha-module.git captcha ``` - -### Module installation from zip package - -* Make a new folder "captcha" in the **modules/oe/ directory** of your shop installation. -* Download the https://github.com/OXIDprojects/captcha-module/archive/master.zip file and unpack it into the created folder. +And add repository to root composer: +```bash +composer config repositories.oxid-projects/captcha-module path "source/modules/oe/captcha" +``` +And install module: +```bash +composer require oxid-projects/captcha-module +vendor/bin/oe-console oe:module:install source/modules/oe/captcha +# And activate +vendor/bin/oe-console oe:module:activate oecaptcha +``` ## Activate Module - Activate the module in the administration panel. +- Or use console +```bash +vendor/bin/oe-console oe:module:activate oecaptcha +``` ## Uninstall -Disable the module in administration area and delete the module folder. +Disable the module in administration area or by executing following shell command. +```bash +vendor/bin/oe-console oe:module:deactivate oecaptcha +``` +If installed over composer (packagist): +```bash +composer remove oxid-projects/captcha-module +``` +else if cloned: +```bash +vendor/bin/oe-console oe:module:uninstall oecaptcha +composer remove oxid-projects/captcha-module +composer config --unset repositories.oxid-projects/captcha-module +# and remove the source itself +rm -rf source/modules/oe/captcha +``` ## License diff --git a/metadata.php b/metadata.php index 6b21e8c..1146a10 100755 --- a/metadata.php +++ b/metadata.php @@ -43,7 +43,7 @@ $aModule = [ 'url' => 'https://www.oxid-esales.com/', 'email' => '', 'controllers' => [ - 'ith_basic_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class, + 'oe_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class, ], 'extend' => [ OxidEsales\Eshop\Application\Controller\ArticleDetailsController::class => OxidProfessionalServices\Captcha\Application\Controller\DetailsController::class, @@ -55,7 +55,7 @@ $aModule = [ OxidEsales\Eshop\Application\Component\Widget\ArticleDetails::class => OxidProfessionalServices\Captcha\Application\Component\Widget\ArticleDetails::class, ], 'templates' => [ - 'oe_captcha.tpl' => 'views/smarty/tpl/oe_captcha.tpl', + 'oe_captcha.tpl' => 'views/smarty/tpl/include/oe_captcha.tpl', ], 'blocks' => [ [ @@ -63,11 +63,6 @@ $aModule = [ 'block' => 'captcha_form', 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', ], - [ - 'template' => 'form/newsletter.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], [ 'template' => 'form/privatesales/invite.tpl', 'block' => 'captcha_form', @@ -78,16 +73,6 @@ $aModule = [ 'block' => 'captcha_form', 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', ], - [ - 'template' => 'form/suggest.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - [ - 'template' => 'form/forgotpwd_email.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], ], 'settings' => [ [ diff --git a/views/admin_twig/smarty/block/oe_captcha_form.tpl b/views/admin_twig/smarty/block/oe_captcha_form.tpl deleted file mode 100644 index 4c9afc7..0000000 --- a/views/admin_twig/smarty/block/oe_captcha_form.tpl +++ /dev/null @@ -1,3 +0,0 @@ -[{$smarty.block.parent}] - -[{include file="oe_captcha.tpl"}] \ No newline at end of file diff --git a/views/admin_twig/smarty/tpl/oe_captcha.tpl b/views/smarty/tpl/include/oe_captcha.tpl similarity index 92% rename from views/admin_twig/smarty/tpl/oe_captcha.tpl rename to views/smarty/tpl/include/oe_captcha.tpl index 4c8b439..e7c5c06 100644 --- a/views/admin_twig/smarty/tpl/oe_captcha.tpl +++ b/views/smarty/tpl/include/oe_captcha.tpl @@ -1,4 +1,4 @@ -[{assign var="oCaptcha" value=$oView->getCaptcha()}] +[{assign var="oCaptcha" value=$oView->getOeCaptcha()}]
diff --git a/views/smarty/tpl/oe_captcha.tpl b/views/smarty/tpl/oe_captcha.tpl deleted file mode 100644 index 4c8b439..0000000 --- a/views/smarty/tpl/oe_captcha.tpl +++ /dev/null @@ -1,20 +0,0 @@ -[{assign var="oCaptcha" value=$oView->getCaptcha()}] - - -
- - -
-
- - [{if $oCaptcha->isImageVisible()}] - - [{else}] - [{$oCaptcha->getText()}] - [{/if}] - - -
-
-
\ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/contact.html.twig b/views/twig/extensions/themes/default/form/contact.html.twig new file mode 100644 index 0000000..cab35c5 --- /dev/null +++ b/views/twig/extensions/themes/default/form/contact.html.twig @@ -0,0 +1,6 @@ +{% extends "form/contact.html.twig" %} + +{% block captcha_form %} + {{ parent() }} + {% include "@oecaptcha/oe_captcha.html.twig" %} +{% endblock %} \ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/pricealarm.html.twig b/views/twig/extensions/themes/default/form/pricealarm.html.twig new file mode 100644 index 0000000..6ea0119 --- /dev/null +++ b/views/twig/extensions/themes/default/form/pricealarm.html.twig @@ -0,0 +1,6 @@ +{% extends "form/pricealarm.html.twig" %} + +{% block captcha_form %} + {{ parent() }} + {% include "@oecaptcha/oe_captcha.html.twig" %} +{% endblock %} \ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/privatesales/invite.html.twig b/views/twig/extensions/themes/default/form/privatesales/invite.html.twig new file mode 100644 index 0000000..9822eb1 --- /dev/null +++ b/views/twig/extensions/themes/default/form/privatesales/invite.html.twig @@ -0,0 +1,6 @@ +{% extends "form/privatesales/invite.html.twig" %} + +{% block captcha_form %} + {{ parent() }} + {% include "@oecaptcha/oe_captcha.html.twig" %} +{% endblock %} \ No newline at end of file diff --git a/views/twig/oe_captcha.html.twig b/views/twig/oe_captcha.html.twig new file mode 100644 index 0000000..0bccbc6 --- /dev/null +++ b/views/twig/oe_captcha.html.twig @@ -0,0 +1,26 @@ +{% set oCaptcha = oView.getCaptcha() %} + +{% block style %} + +{% endblock %} +
+ + +
+
+ + {% if oCaptcha.isImageVisible() %} + + {% else %} + {{ oCaptcha.getText() }} + {% endif %} + + +
+
+
\ No newline at end of file From 8926e6618dded0cc101a2584d7825f06392693c0 Mon Sep 17 00:00:00 2001 From: Gabriel Peleskei Date: Wed, 19 Jul 2023 10:56:36 +0000 Subject: [PATCH 03/15] Finalized module for smarty, added more blocks in templates --- CHANGELOG.md | 4 ++ README.md | 7 +- docs/README.txt | 36 ---------- metadata.php | 10 +++ .../{block => blocks}/oe_captcha_form.tpl | 0 views/smarty/tpl/include/oe_captcha.tpl | 63 ++++++++++++----- views/twig/oe_captcha.html.twig | 69 ++++++++++++------- 7 files changed, 110 insertions(+), 79 deletions(-) delete mode 100755 docs/README.txt rename views/smarty/{block => blocks}/oe_captcha_form.tpl (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f532d8b..67ffc35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed - Suggest dropped out +- /docs folder (no relevant information) + +### Deprecated +- Tests won't work for this release and should be updated in the future. ## [2.0.4] - 22 Oct 2021 diff --git a/README.md b/README.md index 98bfc8c..3922987 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ can submit the following forms: - contact - invite - pricealarm (not bound in twig) + - newsletter (not bound in twig) + - forgotpwd (not bound in twig) The captcha module then validates the submitted value against the expected one and then decides whether to process the request (e.g. send contact mail to shop administrator) or refuse and show an error message instead. @@ -41,8 +43,6 @@ And install module: ```bash composer require oxid-projects/captcha-module vendor/bin/oe-console oe:module:install source/modules/oe/captcha -# And activate -vendor/bin/oe-console oe:module:activate oecaptcha ``` ## Activate Module @@ -51,6 +51,7 @@ vendor/bin/oe-console oe:module:activate oecaptcha - Or use console ```bash vendor/bin/oe-console oe:module:activate oecaptcha +vendor/bin/oe-console oe:cache:clear ``` ## Uninstall @@ -62,10 +63,12 @@ vendor/bin/oe-console oe:module:deactivate oecaptcha If installed over composer (packagist): ```bash composer remove oxid-projects/captcha-module +vendor/bin/oe-console oe:cache:clear ``` else if cloned: ```bash vendor/bin/oe-console oe:module:uninstall oecaptcha +vendor/bin/oe-console oe:cache:clear composer remove oxid-projects/captcha-module composer config --unset repositories.oxid-projects/captcha-module # and remove the source itself diff --git a/docs/README.txt b/docs/README.txt deleted file mode 100755 index 5400211..0000000 --- a/docs/README.txt +++ /dev/null @@ -1,36 +0,0 @@ -==Title== -OE Captcha - -==Author== -OXID eSales AG - -==Prefix== -oe - -==Shop Version== -6.x - -==Version== -1.0.0 - -==Link== -http://www.oxid-esales.com/ - -==Mail== - - -==Description== -OE Captcha Module - -==Installation== -Activate the module in administration area. - -==Extend== - - -==Modules== - -==Modified original templates== - -==Uninstall== -Disable the module in administration area and delete module folder. diff --git a/metadata.php b/metadata.php index 1146a10..7c8f446 100755 --- a/metadata.php +++ b/metadata.php @@ -73,6 +73,16 @@ $aModule = [ 'block' => 'captcha_form', 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', ], + [ + 'template' => 'form/newsletter.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], + [ + 'template' => 'form/forgotpwd_email.tpl', + 'block' => 'captcha_form', + 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', + ], ], 'settings' => [ [ diff --git a/views/smarty/block/oe_captcha_form.tpl b/views/smarty/blocks/oe_captcha_form.tpl similarity index 100% rename from views/smarty/block/oe_captcha_form.tpl rename to views/smarty/blocks/oe_captcha_form.tpl diff --git a/views/smarty/tpl/include/oe_captcha.tpl b/views/smarty/tpl/include/oe_captcha.tpl index e7c5c06..3c13fe4 100644 --- a/views/smarty/tpl/include/oe_captcha.tpl +++ b/views/smarty/tpl/include/oe_captcha.tpl @@ -1,20 +1,47 @@ -[{assign var="oCaptcha" value=$oView->getOeCaptcha()}] - +[{assign var="oCaptcha" value=$oView->getCaptcha()}] +[{block name="body"}] + [{block name="style"}] + + [{/block}] -
- + [{block name="hidden"}] + + [{/block}] -
-
- - [{if $oCaptcha->isImageVisible()}] - - [{else}] - [{$oCaptcha->getText()}] - [{/if}] - - -
-
-
\ No newline at end of file + [{block name="form_group"}] +
+ [{block name="label"}] + + [{/block}] + + [{block name="input_control"}] +
+ [{block name="input_group"}] +
+ [{block name="image_group"}] + + [{if $oCaptcha->isImageVisible()}] + [{block name="image_visible"}] + + [{/block}] + [{else}] + [{block name="image_hidden"}] + [{$oCaptcha->getText()}] + [{/block}] + [{/if}] + + [{/block}] + [{block name="input"}] + + [{/block}] +
+ [{/block}] +
+ [{/block}] +
+ [{/block}] +[{/block}] \ No newline at end of file diff --git a/views/twig/oe_captcha.html.twig b/views/twig/oe_captcha.html.twig index 0bccbc6..528974d 100644 --- a/views/twig/oe_captcha.html.twig +++ b/views/twig/oe_captcha.html.twig @@ -1,26 +1,49 @@ {% set oCaptcha = oView.getCaptcha() %} - -{% block style %} - -{% endblock %} -
- +{% block body %} + {% block style %} + + {% endblock %} + + {% block hidden %} + + {% endblock %} + + {% block form_group %} +
+ {% block label %} + + {% endblock %} -
-
- - {% if oCaptcha.isImageVisible() %} - - {% else %} - {{ oCaptcha.getText() }} - {% endif %} - - -
+ {% block input_control %} +
+ {% block input_group %} +
+ {% block image_group %} + + {% if oCaptcha.isImageVisible() %} + {% block image_visible %} + + {% endblock %} + {% else %} + {% block image_hidden %} + {{ oCaptcha.getText() }} + {% endblock %} + {% endif %} + + {% endblock %} + + {% block input %} + + {% endblock %} +
+ {% endblock %} +
+ {% endblock %}
-
\ No newline at end of file + {% endblock %} +{% endblock %} \ No newline at end of file From 64abb3b36fc16c1ae3f77dce406a5a1eff01daeb Mon Sep 17 00:00:00 2001 From: "LarsStegelitz@Oxid" <48029969+HonkDerHase@users.noreply.github.com> Date: Tue, 15 Aug 2023 14:11:11 +0200 Subject: [PATCH 04/15] Revert "Upgrade to OXID 7 with Twig & Smarty" --- .gitignore | 5 +- .ide-helper.php | 23 -- .../Component/Widget/ArticleDetails.php | 12 - Application/Controller/ContactController.php | 21 -- Application/Controller/DetailsController.php | 23 -- .../Controller/ForgotPasswordController.php | 21 -- .../Controller/ImageGeneratorController.php | 102 ------ Application/Controller/InviteController.php | 21 -- .../Controller/NewsletterController.php | 21 -- .../Controller/PricealarmController.php | 23 -- Application/Core/Module.php | 62 ---- Application/Shared/Captcha.php | 17 - Application/Shared/Connection.php | 25 -- Application/Shared/Options.php | 23 -- .../translations/en/oecaptcha_en_lang.php | 18 -- .../de/oe_captcha_admin_de_lang.php | 9 - .../en/oe_captcha_admin_en_lang.php | 9 - .../de/oe_captcha_admin_de_lang.php | 9 - .../en/oe_captcha_admin_en_lang.php | 9 - CHANGELOG.md | 12 - README.md | 47 +-- .../widget/oecaptchawarticledetails.php | 30 ++ application/views/admin/de/module_options.php | 13 + application/views/admin/en/module_options.php | 13 + application/views/blocks/captcha_form.tpl | 3 + .../views/blocks/captcha_form_forgotpwd.tpl | 3 + application/views/tpl/oecaptcha.tpl | 19 ++ composer.json | 19 +- controllers/oecaptchacontact.php | 44 +++ controllers/oecaptchadetails.php | 52 +++ controllers/oecaptchaforgotpwd.php | 44 +++ controllers/oecaptchainvite.php | 49 +++ controllers/oecaptchanewsletter.php | 44 +++ controllers/oecaptchapricealarm.php | 37 +++ controllers/oecaptchasuggest.php | 52 +++ .../Core/Captcha.php => core/oecaptcha.php | 299 ++++++++---------- core/oecaptchaevents.php | 62 ++++ core/utils/verificationimg.php | 103 ++++++ docs/README.txt | 36 +++ metadata.php | 125 +++----- assets/logo.png => out/pictures/picture.png | Bin .../de/oecaptcha_de_lang.php | 16 +- translations/en/oecaptcha_en_lang.php | 17 + views/smarty/blocks/oe_captcha_form.tpl | 3 - views/smarty/tpl/include/oe_captcha.tpl | 47 --- .../themes/default/form/contact.html.twig | 6 - .../themes/default/form/pricealarm.html.twig | 6 - .../form/privatesales/invite.html.twig | 6 - views/twig/oe_captcha.html.twig | 49 --- 49 files changed, 829 insertions(+), 880 deletions(-) delete mode 100644 .ide-helper.php delete mode 100644 Application/Component/Widget/ArticleDetails.php delete mode 100644 Application/Controller/ContactController.php delete mode 100644 Application/Controller/DetailsController.php delete mode 100644 Application/Controller/ForgotPasswordController.php delete mode 100644 Application/Controller/ImageGeneratorController.php delete mode 100644 Application/Controller/InviteController.php delete mode 100644 Application/Controller/NewsletterController.php delete mode 100644 Application/Controller/PricealarmController.php delete mode 100644 Application/Core/Module.php delete mode 100644 Application/Shared/Captcha.php delete mode 100644 Application/Shared/Connection.php delete mode 100644 Application/Shared/Options.php delete mode 100755 Application/translations/en/oecaptcha_en_lang.php delete mode 100644 Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php delete mode 100644 Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php delete mode 100644 Application/views/admin_twig/de/oe_captcha_admin_de_lang.php delete mode 100644 Application/views/admin_twig/en/oe_captcha_admin_en_lang.php create mode 100644 application/component/widget/oecaptchawarticledetails.php create mode 100644 application/views/admin/de/module_options.php create mode 100644 application/views/admin/en/module_options.php create mode 100644 application/views/blocks/captcha_form.tpl create mode 100644 application/views/blocks/captcha_form_forgotpwd.tpl create mode 100644 application/views/tpl/oecaptcha.tpl create mode 100644 controllers/oecaptchacontact.php create mode 100644 controllers/oecaptchadetails.php create mode 100644 controllers/oecaptchaforgotpwd.php create mode 100644 controllers/oecaptchainvite.php create mode 100644 controllers/oecaptchanewsletter.php create mode 100644 controllers/oecaptchapricealarm.php create mode 100644 controllers/oecaptchasuggest.php rename Application/Core/Captcha.php => core/oecaptcha.php (52%) create mode 100644 core/oecaptchaevents.php create mode 100644 core/utils/verificationimg.php create mode 100755 docs/README.txt rename assets/logo.png => out/pictures/picture.png (100%) rename {Application/translations => translations}/de/oecaptcha_de_lang.php (69%) create mode 100755 translations/en/oecaptcha_en_lang.php delete mode 100644 views/smarty/blocks/oe_captcha_form.tpl delete mode 100644 views/smarty/tpl/include/oe_captcha.tpl delete mode 100644 views/twig/extensions/themes/default/form/contact.html.twig delete mode 100644 views/twig/extensions/themes/default/form/pricealarm.html.twig delete mode 100644 views/twig/extensions/themes/default/form/privatesales/invite.html.twig delete mode 100644 views/twig/oe_captcha.html.twig diff --git a/.gitignore b/.gitignore index 09122f6..485dee6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -.idea/ -.vscode/ -vendor/ -.DS_Store \ No newline at end of file +.idea diff --git a/.ide-helper.php b/.ide-helper.php deleted file mode 100644 index b1df0c6..0000000 --- a/.ide-helper.php +++ /dev/null @@ -1,23 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } -} diff --git a/Application/Controller/DetailsController.php b/Application/Controller/DetailsController.php deleted file mode 100644 index e1543b9..0000000 --- a/Application/Controller/DetailsController.php +++ /dev/null @@ -1,23 +0,0 @@ -getCaptcha()->passCaptcha(false)) { - $this->_iPriceAlarmStatus = 2; - - return; - } - - return parent::addme(); - } -} diff --git a/Application/Controller/ForgotPasswordController.php b/Application/Controller/ForgotPasswordController.php deleted file mode 100644 index 8dda74f..0000000 --- a/Application/Controller/ForgotPasswordController.php +++ /dev/null @@ -1,21 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::forgotpassword(); - } -} diff --git a/Application/Controller/ImageGeneratorController.php b/Application/Controller/ImageGeneratorController.php deleted file mode 100644 index e53422a..0000000 --- a/Application/Controller/ImageGeneratorController.php +++ /dev/null @@ -1,102 +0,0 @@ -emac = Registry::getRequest()->getRequestEscapedParameter('e_mac', null); - if ($this->emac) { - $this->emac = $this->decodeEmac($this->emac); - } - } - - public function render() - { - parent::render(); - - try { - if (!$this->emac) { - throw new StandardException('No e_mac parameter given'); - } - $image = $this->generateVerificationImage(); - if (!$image) { - throw new StandardException('Image generation failed by returning NULL'); - } - header('Content-type: image/png'); - imagepng($image); - imagedestroy($image); - - exit; - } catch (Throwable $e) { - Registry::getLogger()->error(sprintf('%s() | %s', __METHOD__, $e->getMessage()), [$e]); - http_response_code(400); - - exit(1); - } - } - - protected function decodeEmac(string $emac): string - { - $decryptor = new \OxidEsales\Eshop\Core\Decryptor(); - - $key = $this->getOeCaptchaKey(); - - return $decryptor->decrypt($emac, $key); - } - - protected function generateVerificationImage() - { - $image = null; - - switch (true) { - case function_exists('imagecreatetruecolor'): - $image = imagecreatetruecolor($this->imageWidth, $this->imageHeight); - - break; - - case function_exists('imagecreate'): - $image = imagecreate($this->imageWidth, $this->imageHeight); - - break; - - default: - return null; - } - $textX = (int)ceil(($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2); - $textY = (int)ceil(($this->imageHeight - imagefontheight($this->fontSize)) / 2) - 1; - - $colors = [ - 'text' => imagecolorallocate($image, 0, 0, 0), - 'shadow1' => imagecolorallocate($image, 200, 200, 200), - 'shadow2' => imagecolorallocate($image, 100, 100, 100), - 'background' => imagecolorallocate($image, 255, 255, 255), - 'border' => imagecolorallocate($image, 0, 0, 0), - ]; - - imagefill($image, 0, 0, $colors['background']); - imagerectangle($image, 0, 0, $this->imageWidth - 2, $this->imageHeight - 2, $colors['border']); - imagestring($image, $this->fontSize, $textX + 1, $textY + 0, $this->emac, $colors['shadow2']); - imagestring($image, $this->fontSize, $textX + 0, $textY + 1, $this->emac, $colors['shadow1']); - imagestring($image, $this->fontSize, $textX, $textY, $this->emac, $colors['text']); - - return $image; - } -} diff --git a/Application/Controller/InviteController.php b/Application/Controller/InviteController.php deleted file mode 100644 index 42e3e4d..0000000 --- a/Application/Controller/InviteController.php +++ /dev/null @@ -1,21 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } -} diff --git a/Application/Controller/NewsletterController.php b/Application/Controller/NewsletterController.php deleted file mode 100644 index ddd78bd..0000000 --- a/Application/Controller/NewsletterController.php +++ /dev/null @@ -1,21 +0,0 @@ -getCaptcha()->passCaptcha()) { - return false; - } - - return parent::send(); - } -} diff --git a/Application/Controller/PricealarmController.php b/Application/Controller/PricealarmController.php deleted file mode 100644 index cc8c455..0000000 --- a/Application/Controller/PricealarmController.php +++ /dev/null @@ -1,23 +0,0 @@ -getCaptcha()->passCaptcha(false)) { - $this->_iPriceAlarmStatus = 2; - - return; - } - - return parent::addme(); - } -} diff --git a/Application/Core/Module.php b/Application/Core/Module.php deleted file mode 100644 index 7e7edbd..0000000 --- a/Application/Core/Module.php +++ /dev/null @@ -1,62 +0,0 @@ -activate(); - } - - public static function onDeactivate(): void - { - static::getInstance()->deactivate(); - } - - public function createTable(): void - { - $this->getDb()->executeStatement(' - CREATE TABLE IF NOT EXISTS `oecaptcha` (' . - "`OXID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Captcha id'," . - "`OXHASH` char(32) NOT NULL default '' COMMENT 'Hash'," . - "`OXTIME` int(11) NOT NULL COMMENT 'Validation time'," . - "`OXTIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT 'Timestamp'," . - 'PRIMARY KEY (`OXID`), ' . - 'KEY `OXID` (`OXID`,`OXHASH`), ' . - 'KEY `OXTIME` (`OXTIME`) ' . - ") ENGINE=MEMORY AUTO_INCREMENT=1 COMMENT 'If session is not available, this is where captcha information is stored'; - "); - } - - public function dropTable(): void - { - $this->getDb()->executeStatement('DROP TABLE IF EXISTS `oecaptcha`;'); - } - - public function activate(): void - { - $this->createTable(); - } - - public function deactivate(): void - { - $this->dropTable(); - } -} diff --git a/Application/Shared/Captcha.php b/Application/Shared/Captcha.php deleted file mode 100644 index 0ba062e..0000000 --- a/Application/Shared/Captcha.php +++ /dev/null @@ -1,17 +0,0 @@ -oeCaptcha ??= CaptchaCore::getInstance(); - } -} diff --git a/Application/Shared/Connection.php b/Application/Shared/Connection.php deleted file mode 100644 index 625f1b3..0000000 --- a/Application/Shared/Connection.php +++ /dev/null @@ -1,25 +0,0 @@ -getContainer(); - - return $container->get(QueryBuilderFactoryInterface::class)->create(); - } - - public function getDb(): \Doctrine\DBAL\Connection - { - return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get(); - } -} diff --git a/Application/Shared/Options.php b/Application/Shared/Options.php deleted file mode 100644 index 1391e1e..0000000 --- a/Application/Shared/Options.php +++ /dev/null @@ -1,23 +0,0 @@ -getContainer()->get(ModuleSettingServiceInterface::class); - $key = $bridge->getString('oecaptchakey', 'oecaptcha')->toString(); - if (!trim($key)) { - return Captcha::ENCRYPT_KEY; - } - - return $key; - } -} diff --git a/Application/translations/en/oecaptcha_en_lang.php b/Application/translations/en/oecaptcha_en_lang.php deleted file mode 100755 index 0c84406..0000000 --- a/Application/translations/en/oecaptcha_en_lang.php +++ /dev/null @@ -1,18 +0,0 @@ - 'UTF-8', - 'MESSAGE_WRONG_VERIFICATION_CODE' => 'The verification code you entered is not correct. Please try again.', - 'OECAPTCHA_PLACEHOLDER' => 'Prüfcode hier eingeben', - -]; diff --git a/Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php b/Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php deleted file mode 100644 index 5b16ac8..0000000 --- a/Application/views/admin_smarty/de/oe_captcha_admin_de_lang.php +++ /dev/null @@ -1,9 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'Allgemein', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -]; diff --git a/Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php b/Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php deleted file mode 100644 index 2ecd391..0000000 --- a/Application/views/admin_smarty/en/oe_captcha_admin_en_lang.php +++ /dev/null @@ -1,9 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'General', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -]; diff --git a/Application/views/admin_twig/de/oe_captcha_admin_de_lang.php b/Application/views/admin_twig/de/oe_captcha_admin_de_lang.php deleted file mode 100644 index 5b16ac8..0000000 --- a/Application/views/admin_twig/de/oe_captcha_admin_de_lang.php +++ /dev/null @@ -1,9 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'Allgemein', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -]; diff --git a/Application/views/admin_twig/en/oe_captcha_admin_en_lang.php b/Application/views/admin_twig/en/oe_captcha_admin_en_lang.php deleted file mode 100644 index 2ecd391..0000000 --- a/Application/views/admin_twig/en/oe_captcha_admin_en_lang.php +++ /dev/null @@ -1,9 +0,0 @@ - 'UTF-8', - 'SHOP_MODULE_GROUP_main' => 'General', - 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', -]; diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ffc35..ef2c2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,19 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Security -## [7.0.0] - 18 Jul 2023 -### Changed -- PHP 8.0 compatibility -- OXID 7.0 compatibility -- Twig & Smarty Support -- Major version bump to 7.0.0 to match OXID 7.0 compatibility -### Removed -- Suggest dropped out -- /docs folder (no relevant information) - -### Deprecated -- Tests won't work for this release and should be updated in the future. ## [2.0.4] - 22 Oct 2021 diff --git a/README.md b/README.md index 3922987..dd83b41 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,8 @@ It is used to ensure that only a user who can read the distorted characters and can submit the following forms: - contact - invite - - pricealarm (not bound in twig) - - newsletter (not bound in twig) - - forgotpwd (not bound in twig) + - pricealarm + - suggest The captcha module then validates the submitted value against the expected one and then decides whether to process the request (e.g. send contact mail to shop administrator) or refuse and show an error message instead. @@ -25,55 +24,29 @@ Please proceed with one of the following ways to install the module: In order to install the module via composer, run the following commands in commandline of your shop base directory (where the shop's composer.json file resides). -```bash +``` composer require oxid-projects/captcha-module ``` ### Module installation via repository cloning Clone the module to your OXID eShop **modules/oe/** directory: -```bash +``` git clone https://github.com/OXIDprojects/captcha-module.git captcha ``` -And add repository to root composer: -```bash -composer config repositories.oxid-projects/captcha-module path "source/modules/oe/captcha" -``` -And install module: -```bash -composer require oxid-projects/captcha-module -vendor/bin/oe-console oe:module:install source/modules/oe/captcha -``` + +### Module installation from zip package + +* Make a new folder "captcha" in the **modules/oe/ directory** of your shop installation. +* Download the https://github.com/OXIDprojects/captcha-module/archive/master.zip file and unpack it into the created folder. ## Activate Module - Activate the module in the administration panel. -- Or use console -```bash -vendor/bin/oe-console oe:module:activate oecaptcha -vendor/bin/oe-console oe:cache:clear -``` ## Uninstall -Disable the module in administration area or by executing following shell command. -```bash -vendor/bin/oe-console oe:module:deactivate oecaptcha -``` -If installed over composer (packagist): -```bash -composer remove oxid-projects/captcha-module -vendor/bin/oe-console oe:cache:clear -``` -else if cloned: -```bash -vendor/bin/oe-console oe:module:uninstall oecaptcha -vendor/bin/oe-console oe:cache:clear -composer remove oxid-projects/captcha-module -composer config --unset repositories.oxid-projects/captcha-module -# and remove the source itself -rm -rf source/modules/oe/captcha -``` +Disable the module in administration area and delete the module folder. ## License diff --git a/application/component/widget/oecaptchawarticledetails.php b/application/component/widget/oecaptchawarticledetails.php new file mode 100644 index 0000000..773159e --- /dev/null +++ b/application/component/widget/oecaptchawarticledetails.php @@ -0,0 +1,30 @@ +captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + return $this->captcha; + } +} diff --git a/application/views/admin/de/module_options.php b/application/views/admin/de/module_options.php new file mode 100644 index 0000000..8440e95 --- /dev/null +++ b/application/views/admin/de/module_options.php @@ -0,0 +1,13 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'Allgemein', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +); diff --git a/application/views/admin/en/module_options.php b/application/views/admin/en/module_options.php new file mode 100644 index 0000000..b9b8e88 --- /dev/null +++ b/application/views/admin/en/module_options.php @@ -0,0 +1,13 @@ + 'UTF-8', + 'SHOP_MODULE_GROUP_main' => 'General', + 'SHOP_MODULE_oecaptchakey' => 'Captcha Key', +); diff --git a/application/views/blocks/captcha_form.tpl b/application/views/blocks/captcha_form.tpl new file mode 100644 index 0000000..531645c --- /dev/null +++ b/application/views/blocks/captcha_form.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha.tpl" labelCssClass="col-lg-2" inputCssClass="col-lg-10"}] diff --git a/application/views/blocks/captcha_form_forgotpwd.tpl b/application/views/blocks/captcha_form_forgotpwd.tpl new file mode 100644 index 0000000..5171b71 --- /dev/null +++ b/application/views/blocks/captcha_form_forgotpwd.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha.tpl" labelCssClass="col-md-3" inputCssClass="col-md-9"}] diff --git a/application/views/tpl/oecaptcha.tpl b/application/views/tpl/oecaptcha.tpl new file mode 100644 index 0000000..be78fb2 --- /dev/null +++ b/application/views/tpl/oecaptcha.tpl @@ -0,0 +1,19 @@ +[{assign var="oCaptcha" value=$oView->getCaptcha()}] + + +
+ + +
+
+ + [{if $oCaptcha->isImageVisible()}] + + [{else}] + [{$oCaptcha->getText()}] + [{/if}] + + +
+
+
\ No newline at end of file diff --git a/composer.json b/composer.json index 0c45897..b24f871 100644 --- a/composer.json +++ b/composer.json @@ -2,13 +2,7 @@ "name": "oxid-projects/captcha-module", "description": "This is Captcha module for OXID eShop.", "type": "oxideshop-module", - "version": "7.0.0", - "keywords": [ - "oxid", - "modules", - "eShop", - "captcha" - ], + "keywords": ["oxid", "modules", "eShop", "captcha"], "homepage": "https://www.oxid-esales.com/en/home.html", "license": [ "GPL-3.0", @@ -18,14 +12,5 @@ "oxideshop": { "target-directory": "oe/captcha" } - }, - "require": { - "oxid-esales/oxideshop-ce": "^7.0", - "ext-gd": "*" - }, - "autoload": { - "psr-4": { - "OxidProfessionalServices\\Captcha\\": "./" - } } -} \ No newline at end of file +} diff --git a/controllers/oecaptchacontact.php b/controllers/oecaptchacontact.php new file mode 100644 index 0000000..b9af7d9 --- /dev/null +++ b/controllers/oecaptchacontact.php @@ -0,0 +1,44 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } + +} diff --git a/controllers/oecaptchadetails.php b/controllers/oecaptchadetails.php new file mode 100644 index 0000000..a2056e3 --- /dev/null +++ b/controllers/oecaptchadetails.php @@ -0,0 +1,52 @@ +getCaptcha()->passCaptcha(false)) { + $this->_iPriceAlarmStatus = 2; + return; + } + + return parent::addme(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + return $this->captcha; + } +} diff --git a/controllers/oecaptchaforgotpwd.php b/controllers/oecaptchaforgotpwd.php new file mode 100644 index 0000000..7158f89 --- /dev/null +++ b/controllers/oecaptchaforgotpwd.php @@ -0,0 +1,44 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::forgotpassword(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } + +} diff --git a/controllers/oecaptchainvite.php b/controllers/oecaptchainvite.php new file mode 100644 index 0000000..f849ec9 --- /dev/null +++ b/controllers/oecaptchainvite.php @@ -0,0 +1,49 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } + +} diff --git a/controllers/oecaptchanewsletter.php b/controllers/oecaptchanewsletter.php new file mode 100644 index 0000000..caf7000 --- /dev/null +++ b/controllers/oecaptchanewsletter.php @@ -0,0 +1,44 @@ +getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } + +} diff --git a/controllers/oecaptchapricealarm.php b/controllers/oecaptchapricealarm.php new file mode 100644 index 0000000..ddea7eb --- /dev/null +++ b/controllers/oecaptchapricealarm.php @@ -0,0 +1,37 @@ + pricealarm. + */ +class oeCaptchaPricealarm extends oeCaptchaPricealarm_parent +{ + /** + * Validates email + * address. If email is wrong - returns false and exits. If email + * address is OK - creates prcealarm object and saves it + * (oxpricealarm::save()). Sends pricealarm notification mail + * to shop owner. + * + * @return bool false on error + */ + public function addme() + { + //control captcha + $captcha = oxNew('oeCaptcha'); + if (!$captcha->passCaptcha(false)) { + $this->_iPriceAlarmStatus = 2; + + return; + } + + return parent::addme(); + } +} diff --git a/controllers/oecaptchasuggest.php b/controllers/oecaptchasuggest.php new file mode 100644 index 0000000..73d1db8 --- /dev/null +++ b/controllers/oecaptchasuggest.php @@ -0,0 +1,52 @@ +editval, error + * + * @return null + */ + public function send() + { + // spam spider prevension + if (!$this->getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } +} diff --git a/Application/Core/Captcha.php b/core/oecaptcha.php similarity index 52% rename from Application/Core/Captcha.php rename to core/oecaptcha.php index cba5d81..2959fc6 100644 --- a/Application/Core/Captcha.php +++ b/core/oecaptcha.php @@ -1,55 +1,47 @@ text) { $this->text = ''; - - for ($i = 0; $i < $this->macLength; ++$i) { + for ($i = 0; $i < $this->macLength; $i++) { $this->text .= strtolower($this->macChars[rand(0, strlen($this->macChars) - 1)]); } } @@ -67,7 +58,38 @@ class Captcha } /** - * Returns given string captcha hash. + * Returns text hash + * + * @param string $text User supplie text + * + * @return string + */ + public function getHash($text = null) + { + // inserting captcha record + $time = time() + $this->timeout; + $textHash = $this->getTextHash($text); + + // if session is started - storing captcha info here + $session = $this->getSession(); + if ($session->isSessionStarted()) { + $hash = oxUtilsObject::getInstance()->generateUID(); + $hashArray = $session->getVariable('captchaHashes'); + $hashArray[$hash] = array($textHash => $time); + $session->setVariable('captchaHashes', $hashArray); + } else { + $database = DatabaseProvider::getDb(); + $query = "insert into oecaptcha (oxhash, oxtime) values (" . + $database->quote($textHash) . ", " . $database->quote($time) . ")"; + $database->execute($query); + $hash = $database->getOne('select LAST_INSERT_ID()', false, false); + } + + return $hash; + } + + /** + * Returns given string captcha hash * * @param string $text string to hash * @@ -84,9 +106,36 @@ class Captcha } /** - * Check if captcha is passed. + * Returns url to CAPTCHA image generator. * - * @param mixed $displayError + * @return string + */ + public function getImageUrl() + { + $config = \OxidEsales\Eshop\Core\Registry::getConfig(); + $url = $config->getCurrentShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac='; + $key = $config->getConfigParam('oecaptchakey'); + + $key = $key ? $key : $config->getConfigParam('sConfigKey'); + + $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); + $url .= $encryptor->encrypt($this->getText(), $key); + + return $url; + } + + /** + * Checks if image could be generated + * + * @return bool + */ + public function isImageVisible() + { + return ((function_exists('imagecreatetruecolor') || function_exists('imagecreate')) && $this->getConfig()->getConfigParam('iUseGDVersion') > 1); + } + + /** + * Check if captcha is passed. * * @return bool */ @@ -95,8 +144,8 @@ class Captcha $return = true; // spam spider prevention - $mac = Registry::getRequest()->getRequestParameter('c_mac'); - $macHash = Registry::getRequest()->getRequestParameter('c_mach'); + $mac = $this->getConfig()->getRequestParameter('c_mac'); + $macHash = $this->getConfig()->getRequestParameter('c_mach'); if (!$this->pass($mac, $macHash)) { $return = false; @@ -104,139 +153,12 @@ class Captcha if (!$return && $displayError) { // even if there is no exception, use this as a default display method - Registry::getUtilsView()->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE'); + oxRegistry::get('oxUtilsView')->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE'); } return $return; } - /** - * Checks if image could be generated. - * - * @return bool - */ - public function isImageVisible() - { - return (function_exists('imagecreatetruecolor') || function_exists('imagecreate')) && Registry::getConfig()->getConfigParam('iUseGDVersion') > 1; - } - - /** - * Returns url to CAPTCHA image generator. - * - * @return string - */ - public function getImageUrl() - { - $config = Registry::getConfig(); - $key = $this->getOeCaptchaKey(); - $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); - - return $config->getCurrentShopUrl() . sprintf('?cl=oe_captcha_generator&e_mac=%s&shp=%d', $encryptor->encrypt($this->getText(), $key), $config->getShopId()); - } - - /** - * Returns text hash. - * - * @param string $text User supplie text - * - * @return string - */ - public function getHash($text = null) - { - // inserting captcha record - $time = time() + $this->timeout; - $textHash = $this->getTextHash($text); - - // if session is started - storing captcha info here - $session = Registry::getSession(); - if ($session->isSessionStarted()) { - $hash = UtilsObject::getInstance()->generateUID(); - $hashArray = $session->getVariable('captchaHashes'); - $hashArray[$hash] = [$textHash => $time]; - $session->setVariable('captchaHashes', $hashArray); - } else { - $q = $this->getQueryBuilder(); - $q->insert('oecaptcha') - ->values( - [ - 'oxhash' => '?', - 'oxtime' => '?', - ] - )->setParameter(0, $textHash)->setParameter(1, $time); - $q->execute(); - $hash = $q->getConnection()->lastInsertId(); - } - - return $hash; - } - - /** - * Checks for DB captcha hash validity. - * - * @param int $macHash hash key - * @param string $hash captcha hash - * @param int $time check time - * - * @return bool - */ - protected function passFromDb($macHash, $hash, $time) - { - $q = $this->getQueryBuilder(); - $q->select('1') - ->from('oecaptcha') - ->where('oxid = :macHash') - ->andWhere('oxhash = :hash') - ->setParameter('macHash', $macHash) - ->setParameter('hash', $hash); - $pass = (bool) $q->execute()->fetchOne(); - if ($pass) { - // cleanup - $q = $this->getQueryBuilder() - ->delete('oecaptcha') - ->where('oxid = :macHash') - ->andWhere('oxhash = :hash') - ->setParameter('macHash', $macHash) - ->setParameter('hash', $hash); - $q->execute(); - } - - // garbage cleanup - $q = $this->getQueryBuilder() - ->delete('oecaptcha') - ->where('oxtime < :time') - ->setParameter('time', $time); - $q->execute(); - - return $pass; - } - - /** - * Checks for session captcha hash validity. - * - * @param string $macHash hash key - * @param string $hash captcha hash - * @param int $time check time - * - * @return bool - */ - protected function passFromSession($macHash, $hash, $time) - { - $pass = null; - $session = Registry::getSession(); - - if ($hashArray = $session->getVariable('captchaHashes')) { - $pass = (isset($hashArray[$macHash][$hash]) && $hashArray[$macHash][$hash] >= $time) ? true : false; - unset($hashArray[$macHash]); - if (!empty($hashArray)) { - $session->setVariable('captchaHashes', $hashArray); - } else { - $session->deleteVariable('captchaHashes'); - } - } - - return $pass; - } - /** * Verifies captcha input vs supplied hash. Returns true on success. * @@ -252,10 +174,67 @@ class Captcha $pass = $this->passFromSession($macHash, $hash, $time); // if captcha info was NOT stored in session - if (null === $pass) { + if ($pass === null) { $pass = $this->passFromDb((int) $macHash, $hash, $time); } return (bool) $pass; } + + /** + * Checks for session captcha hash validity + * + * @param string $macHash hash key + * @param string $hash captcha hash + * @param int $time check time + * + * @return bool + */ + protected function passFromSession($macHash, $hash, $time) + { + $pass = null; + $session = $this->getSession(); + + if (($hashArray = $session->getVariable('captchaHashes'))) { + $pass = (isset($hashArray[$macHash][$hash]) && $hashArray[$macHash][$hash] >= $time) ? true : false; + unset($hashArray[$macHash]); + if (!empty($hashArray)) { + $session->setVariable('captchaHashes', $hashArray); + } else { + $session->deleteVariable('captchaHashes'); + } + } + + return $pass; + } + + /** + * Checks for DB captcha hash validity + * + * @param int $macHash hash key + * @param string $hash captcha hash + * @param int $time check time + * + * @return bool + */ + protected function passFromDb($macHash, $hash, $time) + { + $database = DatabaseProvider::getDb(); + $where = "where oxid = " . $database->quote($macHash) . " and oxhash = " . $database->quote($hash); + $query = "select 1 from oecaptcha " . $where; + $pass = (bool) $database->getOne($query, false, false); + + if ($pass) { + // cleanup + $query = "delete from oecaptcha " . $where; + $database->execute($query); + } + + // garbage cleanup + $query = "delete from oecaptcha where oxtime < $time"; + $database->execute($query); + + return $pass; + } + } diff --git a/core/oecaptchaevents.php b/core/oecaptchaevents.php new file mode 100644 index 0000000..f647ee6 --- /dev/null +++ b/core/oecaptchaevents.php @@ -0,0 +1,62 @@ +execute($query); + } + + /** + * Remove table oecaptcha. + * NOTE: table oecaptcha contains temporary data if any and can be + * removed without side effects on module deactivation + */ + public static function removeCaptchaTable() + { + $query = "DROP TABLE IF EXISTS `oecaptcha`"; + + DatabaseProvider::getDb()->execute($query); + } + + /** + * Execute action on activate event + * + * @return null + */ + public static function onActivate() + { + self::addCaptchaTable(); + } + + /** + * Execute action on deactivate event + * + * @return null + */ + public static function onDeactivate() + { + self::removeCaptchaTable(); + } +} diff --git a/core/utils/verificationimg.php b/core/utils/verificationimg.php new file mode 100644 index 0000000..769931e --- /dev/null +++ b/core/utils/verificationimg.php @@ -0,0 +1,103 @@ +getConfigParam('oecaptchakey'); + if (empty($key)) { + $key = getOxConfKey(); + } + + return $decryptor->decrypt($value, $key); + } +} + +if (!function_exists('getOxConfKey')) { + + /** + * Get default config key. + * + * @return string + */ + function getOxConfKey() + { + $config = oxRegistry::getConfig(); + $configKey = $config->getConfigParam('sConfigKey') ?: \OxidEsales\Eshop\Core\Config::DEFAULT_CONFIG_KEY; + return $configKey; + } + +} + +$mac = strRem($emac); +generateVerificationImg($mac); diff --git a/docs/README.txt b/docs/README.txt new file mode 100755 index 0000000..5400211 --- /dev/null +++ b/docs/README.txt @@ -0,0 +1,36 @@ +==Title== +OE Captcha + +==Author== +OXID eSales AG + +==Prefix== +oe + +==Shop Version== +6.x + +==Version== +1.0.0 + +==Link== +http://www.oxid-esales.com/ + +==Mail== + + +==Description== +OE Captcha Module + +==Installation== +Activate the module in administration area. + +==Extend== + + +==Modules== + +==Modified original templates== + +==Uninstall== +Disable the module in administration area and delete module folder. diff --git a/metadata.php b/metadata.php index 7c8f446..b8e7bd9 100755 --- a/metadata.php +++ b/metadata.php @@ -1,9 +1,6 @@ Module::ID, - 'title' => [ +$aModule = array( + 'id' => 'oecaptcha', + 'title' => array( 'de' => 'Simple Captcha', 'en' => 'Simple Captcha', - ], - 'description' => [ + ), + 'description' => array( 'de' => 'OXID eSales Simple Captcha Module', 'en' => 'OXID eSales Simple Captcha Module', - ], - 'thumbnail' => 'logo.png', - 'version' => Module::VERSION, - 'author' => 'OXID eSales AG', - 'url' => 'https://www.oxid-esales.com/', - 'email' => '', - 'controllers' => [ - 'oe_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class, - ], - 'extend' => [ - OxidEsales\Eshop\Application\Controller\ArticleDetailsController::class => OxidProfessionalServices\Captcha\Application\Controller\DetailsController::class, - OxidEsales\Eshop\Application\Controller\ContactController::class => OxidProfessionalServices\Captcha\Application\Controller\ContactController::class, - OxidEsales\Eshop\Application\Controller\ForgotPasswordController::class => OxidProfessionalServices\Captcha\Application\Controller\ForgotPasswordController::class, - OxidEsales\Eshop\Application\Controller\InviteController::class => OxidProfessionalServices\Captcha\Application\Controller\InviteController::class, - OxidEsales\Eshop\Application\Controller\NewsletterController::class => OxidProfessionalServices\Captcha\Application\Controller\NewsletterController::class, - OxidEsales\Eshop\Application\Controller\PriceAlarmController::class => OxidProfessionalServices\Captcha\Application\Controller\PricealarmController::class, - OxidEsales\Eshop\Application\Component\Widget\ArticleDetails::class => OxidProfessionalServices\Captcha\Application\Component\Widget\ArticleDetails::class, - ], - 'templates' => [ - 'oe_captcha.tpl' => 'views/smarty/tpl/include/oe_captcha.tpl', - ], - 'blocks' => [ - [ - 'template' => 'form/contact.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - [ - 'template' => 'form/privatesales/invite.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - [ - 'template' => 'form/pricealarm.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - [ - 'template' => 'form/newsletter.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - [ - 'template' => 'form/forgotpwd_email.tpl', - 'block' => 'captcha_form', - 'file' => 'views/smarty/blocks/oe_captcha_form.tpl', - ], - ], - 'settings' => [ - [ - 'group' => 'main', - 'name' => 'oecaptchakey', - 'type' => 'str', - 'value' => '', - ], - ], - 'events' => [ - 'onActivate' => Module::class . '::onActivate', - 'onDeactivate' => Module::class . '::onDeactivate', - ], -]; + ), + 'thumbnail' => 'out/pictures/picture.png', + 'version' => '2.0.4', + 'author' => 'OXID eSales AG', + 'url' => 'http://www.oxid-esales.com/', + 'email' => '', + 'extend' => array('details' => 'oe/captcha/controllers/oecaptchadetails', + 'contact' => 'oe/captcha/controllers/oecaptchacontact', + 'forgotpwd' => 'oe/captcha/controllers/oecaptchaforgotpwd', + 'invite' => 'oe/captcha/controllers/oecaptchainvite', + 'newsletter' => 'oe/captcha/controllers/oecaptchanewsletter', + 'pricealarm' => 'oe/captcha/controllers/oecaptchapricealarm', + 'suggest' => 'oe/captcha/controllers/oecaptchasuggest', + 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails'), + 'files' => array( + 'oecaptcha' => 'oe/captcha/core/oecaptcha.php', + 'oecaptchaEvents' => 'oe/captcha/core/oecaptchaevents.php', + ), + 'templates' => array( + 'oecaptcha.tpl' => 'oe/captcha/application/views/tpl/oecaptcha.tpl', + ), + 'blocks' => array( + array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/privatesales/invite.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), + ), + 'settings' => array( + array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), + ), + 'events' => array( + 'onActivate' => 'oecaptchaevents::onActivate', + 'onDeactivate' => 'oecaptchaevents::onDeactivate' + ), +); diff --git a/assets/logo.png b/out/pictures/picture.png similarity index 100% rename from assets/logo.png rename to out/pictures/picture.png diff --git a/Application/translations/de/oecaptcha_de_lang.php b/translations/de/oecaptcha_de_lang.php similarity index 69% rename from Application/translations/de/oecaptcha_de_lang.php rename to translations/de/oecaptcha_de_lang.php index 02977fe..0effcb4 100755 --- a/Application/translations/de/oecaptcha_de_lang.php +++ b/translations/de/oecaptcha_de_lang.php @@ -1,17 +1,17 @@ 'UTF-8', - 'MESSAGE_WRONG_VERIFICATION_CODE' => 'Der Prüfcode, den Sie eingegeben haben, ist nicht korrekt. Bitte versuchen Sie es erneut!', - 'OECAPTCHA_PLACEHOLDER' => 'Enter verification code here', -]; + 'MESSAGE_WRONG_VERIFICATION_CODE' => 'Der Prüfcode, den Sie eingegeben haben, ist nicht korrekt. Bitte versuchen Sie es erneut!' +); diff --git a/translations/en/oecaptcha_en_lang.php b/translations/en/oecaptcha_en_lang.php new file mode 100755 index 0000000..45abef1 --- /dev/null +++ b/translations/en/oecaptcha_en_lang.php @@ -0,0 +1,17 @@ + 'UTF-8', + 'MESSAGE_WRONG_VERIFICATION_CODE' => "The verification code you entered is not correct. Please try again." +); diff --git a/views/smarty/blocks/oe_captcha_form.tpl b/views/smarty/blocks/oe_captcha_form.tpl deleted file mode 100644 index 4c9afc7..0000000 --- a/views/smarty/blocks/oe_captcha_form.tpl +++ /dev/null @@ -1,3 +0,0 @@ -[{$smarty.block.parent}] - -[{include file="oe_captcha.tpl"}] \ No newline at end of file diff --git a/views/smarty/tpl/include/oe_captcha.tpl b/views/smarty/tpl/include/oe_captcha.tpl deleted file mode 100644 index 3c13fe4..0000000 --- a/views/smarty/tpl/include/oe_captcha.tpl +++ /dev/null @@ -1,47 +0,0 @@ -[{assign var="oCaptcha" value=$oView->getCaptcha()}] -[{block name="body"}] - [{block name="style"}] - - [{/block}] - - [{block name="hidden"}] - - [{/block}] - - [{block name="form_group"}] -
- [{block name="label"}] - - [{/block}] - - [{block name="input_control"}] -
- [{block name="input_group"}] -
- [{block name="image_group"}] - - [{if $oCaptcha->isImageVisible()}] - [{block name="image_visible"}] - - [{/block}] - [{else}] - [{block name="image_hidden"}] - [{$oCaptcha->getText()}] - [{/block}] - [{/if}] - - [{/block}] - [{block name="input"}] - - [{/block}] -
- [{/block}] -
- [{/block}] -
- [{/block}] -[{/block}] \ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/contact.html.twig b/views/twig/extensions/themes/default/form/contact.html.twig deleted file mode 100644 index cab35c5..0000000 --- a/views/twig/extensions/themes/default/form/contact.html.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "form/contact.html.twig" %} - -{% block captcha_form %} - {{ parent() }} - {% include "@oecaptcha/oe_captcha.html.twig" %} -{% endblock %} \ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/pricealarm.html.twig b/views/twig/extensions/themes/default/form/pricealarm.html.twig deleted file mode 100644 index 6ea0119..0000000 --- a/views/twig/extensions/themes/default/form/pricealarm.html.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "form/pricealarm.html.twig" %} - -{% block captcha_form %} - {{ parent() }} - {% include "@oecaptcha/oe_captcha.html.twig" %} -{% endblock %} \ No newline at end of file diff --git a/views/twig/extensions/themes/default/form/privatesales/invite.html.twig b/views/twig/extensions/themes/default/form/privatesales/invite.html.twig deleted file mode 100644 index 9822eb1..0000000 --- a/views/twig/extensions/themes/default/form/privatesales/invite.html.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "form/privatesales/invite.html.twig" %} - -{% block captcha_form %} - {{ parent() }} - {% include "@oecaptcha/oe_captcha.html.twig" %} -{% endblock %} \ No newline at end of file diff --git a/views/twig/oe_captcha.html.twig b/views/twig/oe_captcha.html.twig deleted file mode 100644 index 528974d..0000000 --- a/views/twig/oe_captcha.html.twig +++ /dev/null @@ -1,49 +0,0 @@ -{% set oCaptcha = oView.getCaptcha() %} -{% block body %} - {% block style %} - - {% endblock %} - - {% block hidden %} - - {% endblock %} - - {% block form_group %} -
- {% block label %} - - {% endblock %} - - {% block input_control %} -
- {% block input_group %} -
- {% block image_group %} - - {% if oCaptcha.isImageVisible() %} - {% block image_visible %} - - {% endblock %} - {% else %} - {% block image_hidden %} - {{ oCaptcha.getText() }} - {% endblock %} - {% endif %} - - {% endblock %} - - {% block input %} - - {% endblock %} -
- {% endblock %} -
- {% endblock %} -
- {% endblock %} -{% endblock %} \ No newline at end of file From 0c74177b151f3467a55678d8c8201d8abe8fcb8e Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Wed, 23 Feb 2022 09:20:32 +0100 Subject: [PATCH 05/15] add check for register --- application/component/oeusercomponent.php | 39 +++++++++++++++++ controllers/oecaptcharegister.php | 52 +++++++++++++++++++++++ metadata.php | 7 ++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 application/component/oeusercomponent.php create mode 100644 controllers/oecaptcharegister.php diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php new file mode 100644 index 0000000..bd005b0 --- /dev/null +++ b/application/component/oeusercomponent.php @@ -0,0 +1,39 @@ +captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + return $this->captcha; + } + + public function createUser() + { + if (!$this->getCaptcha()->passCaptcha()) { + return false; + } + + return parent::createUser(); + } +} diff --git a/controllers/oecaptcharegister.php b/controllers/oecaptcharegister.php new file mode 100644 index 0000000..7005fe4 --- /dev/null +++ b/controllers/oecaptcharegister.php @@ -0,0 +1,52 @@ +editval, error + * + * @return null + */ + public function send() + { + // spam spider prevension + if (!$this->getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } +} diff --git a/metadata.php b/metadata.php index b8e7bd9..b37181b 100755 --- a/metadata.php +++ b/metadata.php @@ -44,7 +44,10 @@ $aModule = array( 'newsletter' => 'oe/captcha/controllers/oecaptchanewsletter', 'pricealarm' => 'oe/captcha/controllers/oecaptchapricealarm', 'suggest' => 'oe/captcha/controllers/oecaptchasuggest', - 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails'), + 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails', + \OxidEsales\Eshop\Application\Component\UserComponent::class => 'oe/captcha/application/component/oeusercomponent', + 'register' => 'oe/captcha/controllers/oecaptcharegister' + ), 'files' => array( 'oecaptcha' => 'oe/captcha/core/oecaptcha.php', 'oecaptchaEvents' => 'oe/captcha/core/oecaptchaevents.php', @@ -59,6 +62,8 @@ $aModule = array( array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), + array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl' + ), ), 'settings' => array( array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), From ae340f85693a1c45dbe1511990655aad635bbcd5 Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Mon, 14 Mar 2022 11:14:24 +0100 Subject: [PATCH 06/15] add check for user --- controllers/oecaptchauser.php | 52 +++++++++++++++++++++++++++++++++++ metadata.php | 3 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 controllers/oecaptchauser.php diff --git a/controllers/oecaptchauser.php b/controllers/oecaptchauser.php new file mode 100644 index 0000000..81eb8a6 --- /dev/null +++ b/controllers/oecaptchauser.php @@ -0,0 +1,52 @@ +editval, error + * + * @return null + */ + public function send() + { + // spam spider prevension + if (!$this->getCaptcha()->passCaptcha()) { + return false; + } + + return parent::send(); + } + + /** + * Template variable getter. Returns object of handling CAPTCHA image + * + * @return object + */ + public function getCaptcha() + { + if ($this->captcha === null) { + $this->captcha = oxNew('oeCaptcha'); + } + + return $this->captcha; + } +} diff --git a/metadata.php b/metadata.php index b37181b..1c44928 100755 --- a/metadata.php +++ b/metadata.php @@ -46,7 +46,8 @@ $aModule = array( 'suggest' => 'oe/captcha/controllers/oecaptchasuggest', 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails', \OxidEsales\Eshop\Application\Component\UserComponent::class => 'oe/captcha/application/component/oeusercomponent', - 'register' => 'oe/captcha/controllers/oecaptcharegister' + 'register' => 'oe/captcha/controllers/oecaptcharegister', + 'user' => 'oe/captcha/controllers/oecaptchauser' ), 'files' => array( 'oecaptcha' => 'oe/captcha/core/oecaptcha.php', From 33fe2d8ade9e2ccacc675b25dd8a5e3fe10a0aa4 Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Mon, 16 May 2022 15:14:57 +0200 Subject: [PATCH 07/15] add templates for wave theme --- .../blocks/captcha_form_contact_wave.tpl | 3 +++ .../blocks/captcha_form_forgotpwd_wave.tpl | 3 +++ .../blocks/captcha_form_newsletter_wave.tpl | 3 +++ .../blocks/captcha_form_user_billing_wave.tpl | 3 +++ .../views/blocks/captcha_form_wave.tpl | 3 +++ application/views/tpl/oecaptcha_wave.tpl | 19 +++++++++++++++ metadata.php | 24 ++++++++++++------- 7 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 application/views/blocks/captcha_form_contact_wave.tpl create mode 100644 application/views/blocks/captcha_form_forgotpwd_wave.tpl create mode 100644 application/views/blocks/captcha_form_newsletter_wave.tpl create mode 100644 application/views/blocks/captcha_form_user_billing_wave.tpl create mode 100644 application/views/blocks/captcha_form_wave.tpl create mode 100644 application/views/tpl/oecaptcha_wave.tpl diff --git a/application/views/blocks/captcha_form_contact_wave.tpl b/application/views/blocks/captcha_form_contact_wave.tpl new file mode 100644 index 0000000..8974429 --- /dev/null +++ b/application/views/blocks/captcha_form_contact_wave.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha_wave.tpl" labelCssClass="control-label col-lg-2" inputCssClass="col-lg-5"}] diff --git a/application/views/blocks/captcha_form_forgotpwd_wave.tpl b/application/views/blocks/captcha_form_forgotpwd_wave.tpl new file mode 100644 index 0000000..dbe9680 --- /dev/null +++ b/application/views/blocks/captcha_form_forgotpwd_wave.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha_wave.tpl" labelCssClass="col-lg-2" inputCssClass="col-lg-5"}] diff --git a/application/views/blocks/captcha_form_newsletter_wave.tpl b/application/views/blocks/captcha_form_newsletter_wave.tpl new file mode 100644 index 0000000..8974429 --- /dev/null +++ b/application/views/blocks/captcha_form_newsletter_wave.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha_wave.tpl" labelCssClass="control-label col-lg-2" inputCssClass="col-lg-5"}] diff --git a/application/views/blocks/captcha_form_user_billing_wave.tpl b/application/views/blocks/captcha_form_user_billing_wave.tpl new file mode 100644 index 0000000..71e8bd3 --- /dev/null +++ b/application/views/blocks/captcha_form_user_billing_wave.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha_wave.tpl" labelCssClass="col-lg-3" inputCssClass="col-lg-5"}] diff --git a/application/views/blocks/captcha_form_wave.tpl b/application/views/blocks/captcha_form_wave.tpl new file mode 100644 index 0000000..02388f2 --- /dev/null +++ b/application/views/blocks/captcha_form_wave.tpl @@ -0,0 +1,3 @@ +[{$smarty.block.parent}] + +[{include file="oecaptcha_wave.tpl" labelCssClass="col-lg-3" inputCssClass="col-lg-8"}] diff --git a/application/views/tpl/oecaptcha_wave.tpl b/application/views/tpl/oecaptcha_wave.tpl new file mode 100644 index 0000000..123e276 --- /dev/null +++ b/application/views/tpl/oecaptcha_wave.tpl @@ -0,0 +1,19 @@ +[{assign var="oCaptcha" value=$oView->getCaptcha()}] + + +
+ + +
+
+ + [{if $oCaptcha->isImageVisible()}] + + [{else}] + [{$oCaptcha->getText()}] + [{/if}] + + +
+
+
\ No newline at end of file diff --git a/metadata.php b/metadata.php index 1c44928..7956f40 100755 --- a/metadata.php +++ b/metadata.php @@ -55,16 +55,24 @@ $aModule = array( ), 'templates' => array( 'oecaptcha.tpl' => 'oe/captcha/application/views/tpl/oecaptcha.tpl', + 'oecaptcha_wave.tpl' => 'oe/captcha/application/views/tpl/oecaptcha_wave.tpl', ), 'blocks' => array( - array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/privatesales/invite.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), - array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl' - ), + array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/privatesales/invite.tpl', 'theme' => 'flow', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), + array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + + array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_contact_wave.tpl'), + array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_newsletter_wave.tpl'), + array('template' => 'form/privatesales/invite.tpl', 'theme' => 'wave', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_forgotpwd_wave.tpl'), + array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_user_billing_wave.tpl'), ), 'settings' => array( array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), From c44887803ef374d3d1cc7e4f7484bce7fa213343 Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Mon, 16 May 2022 15:15:35 +0200 Subject: [PATCH 08/15] update Version to 2.0.5 --- metadata.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata.php b/metadata.php index 7956f40..dc334f8 100755 --- a/metadata.php +++ b/metadata.php @@ -33,9 +33,9 @@ $aModule = array( 'en' => 'OXID eSales Simple Captcha Module', ), 'thumbnail' => 'out/pictures/picture.png', - 'version' => '2.0.4', + 'version' => '2.0.5', 'author' => 'OXID eSales AG', - 'url' => 'http://www.oxid-esales.com/', + 'url' => 'https://www.oxid-esales.com/', 'email' => '', 'extend' => array('details' => 'oe/captcha/controllers/oecaptchadetails', 'contact' => 'oe/captcha/controllers/oecaptchacontact', From 4e038ef88572e48f62031793876a170eaab66c96 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 30 Jun 2023 10:29:30 +0200 Subject: [PATCH 09/15] initial preparation for ticket https://support.shopmodule.com/scp/tickets.php?id=11765 --- application/component/oeusercomponent.php | 9 +++ controllers/oecaptchaaccountuser.php | 29 +++++++++ metadata.php | 79 ++++++++++++++++++----- 3 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 controllers/oecaptchaaccountuser.php diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php index bd005b0..473caa7 100644 --- a/application/component/oeusercomponent.php +++ b/application/component/oeusercomponent.php @@ -36,4 +36,13 @@ class oeUserComponent extends oeUserComponent_parent return parent::createUser(); } + + public function changeuser_testvalues() + { + if (!$this->getCaptcha()->passCaptcha()) { + return false; + } + + return parent::changeuser_testvalues(); + } } diff --git a/controllers/oecaptchaaccountuser.php b/controllers/oecaptchaaccountuser.php new file mode 100644 index 0000000..9ed62b5 --- /dev/null +++ b/controllers/oecaptchaaccountuser.php @@ -0,0 +1,29 @@ +captcha === null ) { + $this->captcha = oxNew( 'oeCaptcha' ); + } + + return $this->captcha; + } +} diff --git a/metadata.php b/metadata.php index dc334f8..87b1b65 100755 --- a/metadata.php +++ b/metadata.php @@ -17,6 +17,10 @@ /** * Metadata version */ + +use OxidEsales\Eshop\Application\Component\UserComponent; +use OxidEsales\Eshop\Application\Controller\AccountUserController; + $sMetadataVersion = '1.1'; /** @@ -45,9 +49,10 @@ $aModule = array( 'pricealarm' => 'oe/captcha/controllers/oecaptchapricealarm', 'suggest' => 'oe/captcha/controllers/oecaptchasuggest', 'oxwarticledetails' => 'oe/captcha/application/component/widget/oecaptchawarticledetails', - \OxidEsales\Eshop\Application\Component\UserComponent::class => 'oe/captcha/application/component/oeusercomponent', + UserComponent::class => 'oe/captcha/application/component/oeusercomponent', 'register' => 'oe/captcha/controllers/oecaptcharegister', - 'user' => 'oe/captcha/controllers/oecaptchauser' + 'user' => 'oe/captcha/controllers/oecaptchauser', + AccountUserController::class => 'oe/captcha/controllers/oecaptchaaccountuser' ), 'files' => array( 'oecaptcha' => 'oe/captcha/core/oecaptcha.php', @@ -58,21 +63,63 @@ $aModule = array( 'oecaptcha_wave.tpl' => 'oe/captcha/application/views/tpl/oecaptcha_wave.tpl', ), 'blocks' => array( - array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/privatesales/invite.tpl', 'theme' => 'flow', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), - array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'theme' => 'flow', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/contact.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/newsletter.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/privatesales/invite.tpl', + 'theme' => 'flow', + 'block'=>'captcha_form', + 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/pricealarm.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/suggest.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/forgotpwd_email.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form_forgotpwd.tpl'), + array('template' => 'form/fieldset/user_billing.tpl', + 'block'=>'captcha_form', + 'theme' => 'flow', + 'file'=>'/application/views/blocks/captcha_form.tpl'), - array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_contact_wave.tpl'), - array('template' => 'form/newsletter.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_newsletter_wave.tpl'), - array('template' => 'form/privatesales/invite.tpl', 'theme' => 'wave', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), - array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), - array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), - array('template' => 'form/forgotpwd_email.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_forgotpwd_wave.tpl'), - array('template' => 'form/fieldset/user_billing.tpl', 'block'=>'captcha_form', 'theme' => 'wave', 'file'=>'/application/views/blocks/captcha_form_user_billing_wave.tpl'), + array('template' => 'form/contact.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_contact_wave.tpl'), + array('template' => 'form/newsletter.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_newsletter_wave.tpl'), + array('template' => 'form/privatesales/invite.tpl', + 'theme' => 'wave', + 'block'=>'captcha_form', + 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/pricealarm.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/suggest.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_wave.tpl'), + array('template' => 'form/forgotpwd_email.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_forgotpwd_wave.tpl'), + array('template' => 'form/fieldset/user_billing.tpl', + 'block'=>'captcha_form', + 'theme' => 'wave', + 'file'=>'/application/views/blocks/captcha_form_user_billing_wave.tpl'), ), 'settings' => array( array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), From 3d0025cbc920b68ea720e483e864587878f53317 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 18 Jul 2023 11:41:31 +0200 Subject: [PATCH 10/15] don't show and request captcha if user is logged in --- application/component/oeusercomponent.php | 9 --------- .../views/blocks/captcha_form_user_billing_wave.tpl | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php index 473caa7..bd005b0 100644 --- a/application/component/oeusercomponent.php +++ b/application/component/oeusercomponent.php @@ -36,13 +36,4 @@ class oeUserComponent extends oeUserComponent_parent return parent::createUser(); } - - public function changeuser_testvalues() - { - if (!$this->getCaptcha()->passCaptcha()) { - return false; - } - - return parent::changeuser_testvalues(); - } } diff --git a/application/views/blocks/captcha_form_user_billing_wave.tpl b/application/views/blocks/captcha_form_user_billing_wave.tpl index 71e8bd3..93381d7 100644 --- a/application/views/blocks/captcha_form_user_billing_wave.tpl +++ b/application/views/blocks/captcha_form_user_billing_wave.tpl @@ -1,3 +1,5 @@ [{$smarty.block.parent}] -[{include file="oecaptcha_wave.tpl" labelCssClass="col-lg-3" inputCssClass="col-lg-5"}] +[{if !$oxcmp_user}] + [{include file="oecaptcha_wave.tpl" labelCssClass="col-lg-3" inputCssClass="col-lg-5"}] +[{/if}] From ba5d8d04af450dbff6712e96268e6ed36674868a Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 18 Jul 2023 12:16:37 +0200 Subject: [PATCH 11/15] adjust version informations --- CHANGELOG.md | 3 ++- metadata.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef2c2b6..1355282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Security - +## 2.0.6 - 18 Juli 2023 +- don't request captcha if user is logged in ## [2.0.4] - 22 Oct 2021 diff --git a/metadata.php b/metadata.php index 87b1b65..d1e804d 100755 --- a/metadata.php +++ b/metadata.php @@ -37,7 +37,7 @@ $aModule = array( 'en' => 'OXID eSales Simple Captcha Module', ), 'thumbnail' => 'out/pictures/picture.png', - 'version' => '2.0.5', + 'version' => '2.0.6', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com/', 'email' => '', From 0305d484a31f41293f323ae8fde709918d7c1c9c Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Tue, 5 Sep 2023 14:37:54 +0200 Subject: [PATCH 12/15] Remove complication with PayPal Checkout --- application/component/oeusercomponent.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php index bd005b0..50bb53e 100644 --- a/application/component/oeusercomponent.php +++ b/application/component/oeusercomponent.php @@ -30,6 +30,11 @@ class oeUserComponent extends oeUserComponent_parent public function createUser() { + if(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('fnc') == 'approveOrder') + { + return parent::createUser(); + } + if (!$this->getCaptcha()->passCaptcha()) { return false; } From 5620d6b46048d065b4c60dd96eef800d158c30da Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Tue, 5 Sep 2023 14:43:06 +0200 Subject: [PATCH 13/15] add Version 2.0.7 --- CHANGELOG.md | 3 +++ metadata.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1355282..71116de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Security +## 2.0.7 - 08 September 2023 +- + ## 2.0.6 - 18 Juli 2023 - don't request captcha if user is logged in diff --git a/metadata.php b/metadata.php index d1e804d..9dcdb89 100755 --- a/metadata.php +++ b/metadata.php @@ -37,7 +37,7 @@ $aModule = array( 'en' => 'OXID eSales Simple Captcha Module', ), 'thumbnail' => 'out/pictures/picture.png', - 'version' => '2.0.6', + 'version' => '2.0.7', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com/', 'email' => '', From a2fdc172474fc2e3e2501883b7b72e87c2ae3cfd Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Wed, 15 Nov 2023 14:38:08 +0100 Subject: [PATCH 14/15] =?UTF-8?q?Ausnahmebedingung=20f=C3=BCr=20Amazon=20P?= =?UTF-8?q?ay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/component/oeusercomponent.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php index 50bb53e..103a186 100644 --- a/application/component/oeusercomponent.php +++ b/application/component/oeusercomponent.php @@ -30,6 +30,16 @@ class oeUserComponent extends oeUserComponent_parent public function createUser() { + ob_start(); + debug_print_backtrace(); + $trace = ob_get_contents(); + ob_end_clean(); + + if(str_contains($trace, 'initAmazonPayExpress')) + { + return parent::createUser(); + } + if(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('fnc') == 'approveOrder') { return parent::createUser(); From 45657767e4a5ca7c0165bfa44a097e4c9dffa889 Mon Sep 17 00:00:00 2001 From: MarkusGaertner Date: Thu, 16 Nov 2023 09:29:03 +0100 Subject: [PATCH 15/15] mod CHANGELOG.md, add some comments --- CHANGELOG.md | 5 ++++- application/component/oeusercomponent.php | 4 ++++ metadata.php | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71116de..72e36e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Security +## 2.0.8 - 08 September 2023 +- add check for Amazon Pay - no Captcha + ## 2.0.7 - 08 September 2023 -- +- add check for PayPal Checkout - no Captcha ## 2.0.6 - 18 Juli 2023 - don't request captcha if user is logged in diff --git a/application/component/oeusercomponent.php b/application/component/oeusercomponent.php index 103a186..63b4881 100644 --- a/application/component/oeusercomponent.php +++ b/application/component/oeusercomponent.php @@ -30,6 +30,7 @@ class oeUserComponent extends oeUserComponent_parent public function createUser() { + /* START check for Amazon Pay - no Captcha */ ob_start(); debug_print_backtrace(); $trace = ob_get_contents(); @@ -39,11 +40,14 @@ class oeUserComponent extends oeUserComponent_parent { return parent::createUser(); } + /* END check for Amazon Pay - no Captcha / + /* START check for PayPal Checkout - no Captcha */ if(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('fnc') == 'approveOrder') { return parent::createUser(); } + /* START check for PayPal Checkout - no Captcha */ if (!$this->getCaptcha()->passCaptcha()) { return false; diff --git a/metadata.php b/metadata.php index 9dcdb89..9aaf073 100755 --- a/metadata.php +++ b/metadata.php @@ -37,7 +37,7 @@ $aModule = array( 'en' => 'OXID eSales Simple Captcha Module', ), 'thumbnail' => 'out/pictures/picture.png', - 'version' => '2.0.7', + 'version' => '2.0.8', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com/', 'email' => '',