twig support tested manually

This commit is contained in:
Gabriel Peleskei 2023-07-19 09:05:40 +00:00
parent bd415ccb3e
commit e802847f06
19 changed files with 97 additions and 69 deletions

View File

@ -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']);

View File

@ -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());
}
/**

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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',
];

View File

@ -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',
];

View File

@ -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

View File

@ -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' => [
[

View File

@ -1,3 +0,0 @@
[{$smarty.block.parent}]
[{include file="oe_captcha.tpl"}]

View File

@ -1,4 +1,4 @@
[{assign var="oCaptcha" value=$oView->getCaptcha()}]
[{assign var="oCaptcha" value=$oView->getOeCaptcha()}]
<input type="hidden" name="c_mach" value="[{$oCaptcha->getHash()}]" />
<div class="form-group verify">

View File

@ -1,20 +0,0 @@
[{assign var="oCaptcha" value=$oView->getCaptcha()}]
<input type="hidden" name="c_mach" value="[{$oCaptcha->getHash()}]" />
<div class="form-group verify">
<label class="req control-label col-lg-2" for="c_mac">[{oxmultilang ident="VERIFICATION_CODE"}]</label>
<div class="col-lg-10 controls">
<div class="input-group">
<span class="input-group-addon">
[{if $oCaptcha->isImageVisible()}]
<img src="[{$oCaptcha->getImageUrl()}]" alt="">
[{else}]
<span class="verificationCode" id="verifyTextCode">[{$oCaptcha->getText()}]</span>
[{/if}]
</span>
<input type="text" data-fieldsize="verify" name="c_mac" value=""
class="form-control js-oxValidate js-oxValidate_notEmpty" required>
</div>
</div>
</div>

View File

@ -0,0 +1,6 @@
{% extends "form/contact.html.twig" %}
{% block captcha_form %}
{{ parent() }}
{% include "@oecaptcha/oe_captcha.html.twig" %}
{% endblock %}

View File

@ -0,0 +1,6 @@
{% extends "form/pricealarm.html.twig" %}
{% block captcha_form %}
{{ parent() }}
{% include "@oecaptcha/oe_captcha.html.twig" %}
{% endblock %}

View File

@ -0,0 +1,6 @@
{% extends "form/privatesales/invite.html.twig" %}
{% block captcha_form %}
{{ parent() }}
{% include "@oecaptcha/oe_captcha.html.twig" %}
{% endblock %}

View File

@ -0,0 +1,26 @@
{% set oCaptcha = oView.getCaptcha() %}
<input type="hidden" name="c_mach" value="{{ oCaptcha.getHash() }}" />
{% block style %}
<style>
.oecaptcha {padding: 0 .75rem;}
.oecaptcha-group {display: flex; align-items: center; gap: 2ch;}
.oecaptcha-container {display: grid; place-items: center;}
</style>
{% endblock %}
<div class="form-group verify oecaptcha mb-3">
<label class="req control-label col-lg-2" for="c_mac">{{ translate({ ident: "VERIFICATION_CODE" }) }}</label>
<div class="col-lg-10 controls oecaptcha-group-container">
<div class="input-group oecaptcha-group">
<span class="input-group-addon oecaptcha-container">
{% if oCaptcha.isImageVisible() %}
<img src="{{ oCaptcha.getImageUrl() }}" alt="">
{% else %}
<span class="verificationCode" id="verifyTextCode">{{ oCaptcha.getText() }}</span>
{% endif %}
</span>
<input type="text" data-fieldsize="verify" name="c_mac" value="" placeholder="{{ translate({ ident: "OECAPTCHA_PLACEHOLDER" }) }}"
class="form-control js-oxValidate js-oxValidate_notEmpty" required>
</div>
</div>
</div>