mirror of
https://git.d3data.de/3rdParty/captcha-module.git
synced 2024-11-24 07:23:11 +01:00
twig support tested manually
This commit is contained in:
parent
bd415ccb3e
commit
e802847f06
@ -15,8 +15,8 @@ class ImageGeneratorController extends FrontendController
|
|||||||
use Options;
|
use Options;
|
||||||
|
|
||||||
protected $emac;
|
protected $emac;
|
||||||
protected $imageHeight = 18;
|
protected int $imageHeight = 18;
|
||||||
protected $imageWidth = 80;
|
protected int $imageWidth = 80;
|
||||||
protected $fontSize = 14;
|
protected $fontSize = 14;
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
@ -80,8 +80,8 @@ class ImageGeneratorController extends FrontendController
|
|||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$textX = ($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2;
|
$textX = (int)ceil(($this->imageWidth - strlen($this->emac) * imagefontwidth($this->fontSize)) / 2);
|
||||||
$textY = ($this->imageHeight - imagefontheight($this->fontSize)) / 2;
|
$textY = (int)ceil(($this->imageHeight - imagefontheight($this->fontSize)) / 2) - 1;
|
||||||
|
|
||||||
$colors = [
|
$colors = [
|
||||||
'text' => imagecolorallocate($image, 0, 0, 0),
|
'text' => imagecolorallocate($image, 0, 0, 0),
|
||||||
@ -92,7 +92,7 @@ class ImageGeneratorController extends FrontendController
|
|||||||
];
|
];
|
||||||
|
|
||||||
imagefill($image, 0, 0, $colors['background']);
|
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 + 1, $textY + 0, $this->emac, $colors['shadow2']);
|
||||||
imagestring($image, $this->fontSize, $textX + 0, $textY + 1, $this->emac, $colors['shadow1']);
|
imagestring($image, $this->fontSize, $textX + 0, $textY + 1, $this->emac, $colors['shadow1']);
|
||||||
imagestring($image, $this->fontSize, $textX, $textY, $this->emac, $colors['text']);
|
imagestring($image, $this->fontSize, $textX, $textY, $this->emac, $colors['text']);
|
||||||
|
@ -95,8 +95,8 @@ class Captcha
|
|||||||
$return = true;
|
$return = true;
|
||||||
|
|
||||||
// spam spider prevention
|
// spam spider prevention
|
||||||
$mac = Registry::getConfig()->getRequestParameter('c_mac');
|
$mac = Registry::getRequest()->getRequestParameter('c_mac');
|
||||||
$macHash = Registry::getConfig()->getRequestParameter('c_mach');
|
$macHash = Registry::getRequest()->getRequestParameter('c_mach');
|
||||||
|
|
||||||
if (!$this->pass($mac, $macHash)) {
|
if (!$this->pass($mac, $macHash)) {
|
||||||
$return = false;
|
$return = false;
|
||||||
@ -131,7 +131,7 @@ class Captcha
|
|||||||
$key = $this->getOeCaptchaKey();
|
$key = $this->getOeCaptchaKey();
|
||||||
$encryptor = new \OxidEsales\Eshop\Core\Encryptor();
|
$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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,14 +8,10 @@ use OxidProfessionalServices\Captcha\Application\Core\Captcha as CaptchaCore;
|
|||||||
|
|
||||||
trait Captcha
|
trait Captcha
|
||||||
{
|
{
|
||||||
protected ?CaptchaCore $captcha;
|
protected ?CaptchaCore $oeCaptcha;
|
||||||
|
|
||||||
public function getCaptcha(): CaptchaCore
|
public function getCaptcha(): CaptchaCore
|
||||||
{
|
{
|
||||||
if (!$this->captcha) {
|
return $this->oeCaptcha ??= CaptchaCore::getInstance();
|
||||||
$this->captcha = CaptchaCore::getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->captcha;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,16 @@ namespace OxidProfessionalServices\Captcha\Application\Shared;
|
|||||||
|
|
||||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||||
|
use OxidProfessionalServices\Captcha\Application\Core\Captcha;
|
||||||
|
|
||||||
trait Options
|
trait Options
|
||||||
{
|
{
|
||||||
public const ENCRYPT_KEY = 'fq45QS09_fqyx09239QQ';
|
|
||||||
|
|
||||||
public function getOeCaptchaKey(): string
|
public function getOeCaptchaKey(): string
|
||||||
{
|
{
|
||||||
$bridge = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
|
$bridge = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
|
||||||
$key = $bridge->getString('oeCaptchaKey', 'oecaptcha')->toString();
|
$key = $bridge->getString('oecaptchakey', 'oecaptcha')->toString();
|
||||||
if (!trim($key)) {
|
if (!trim($key)) {
|
||||||
return static::ENCRYPT_KEY;
|
return Captcha::ENCRYPT_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $key;
|
return $key;
|
||||||
|
@ -13,4 +13,5 @@ $sLangName = 'Deutsch';
|
|||||||
$aLang = [
|
$aLang = [
|
||||||
'charset' => 'UTF-8',
|
'charset' => '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!',
|
||||||
|
'OECAPTCHA_PLACEHOLDER' => 'Enter verification code here',
|
||||||
];
|
];
|
||||||
|
@ -13,4 +13,6 @@ $sLangName = 'English';
|
|||||||
$aLang = [
|
$aLang = [
|
||||||
'charset' => 'UTF-8',
|
'charset' => 'UTF-8',
|
||||||
'MESSAGE_WRONG_VERIFICATION_CODE' => 'The verification code you entered is not correct. Please try again.',
|
'MESSAGE_WRONG_VERIFICATION_CODE' => 'The verification code you entered is not correct. Please try again.',
|
||||||
|
'OECAPTCHA_PLACEHOLDER' => 'Prüfcode hier eingeben',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
44
README.md
44
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:
|
can submit the following forms:
|
||||||
- contact
|
- contact
|
||||||
- invite
|
- invite
|
||||||
- pricealarm
|
- pricealarm (not bound in twig)
|
||||||
- suggest
|
|
||||||
|
|
||||||
The captcha module then validates the submitted value against the expected one and then decides whether to process the
|
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.
|
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
|
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).
|
(where the shop's composer.json file resides).
|
||||||
|
|
||||||
```
|
```bash
|
||||||
composer require oxid-projects/captcha-module
|
composer require oxid-projects/captcha-module
|
||||||
```
|
```
|
||||||
|
|
||||||
### Module installation via repository cloning
|
### Module installation via repository cloning
|
||||||
|
|
||||||
Clone the module to your OXID eShop **modules/oe/** directory:
|
Clone the module to your OXID eShop **modules/oe/** directory:
|
||||||
```
|
```bash
|
||||||
git clone https://github.com/OXIDprojects/captcha-module.git captcha
|
git clone https://github.com/OXIDprojects/captcha-module.git captcha
|
||||||
```
|
```
|
||||||
|
And add repository to root composer:
|
||||||
### Module installation from zip package
|
```bash
|
||||||
|
composer config repositories.oxid-projects/captcha-module path "source/modules/oe/captcha"
|
||||||
* 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 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 Module
|
||||||
|
|
||||||
- Activate the module in the administration panel.
|
- Activate the module in the administration panel.
|
||||||
|
- Or use console
|
||||||
|
```bash
|
||||||
|
vendor/bin/oe-console oe:module:activate oecaptcha
|
||||||
|
```
|
||||||
|
|
||||||
## Uninstall
|
## 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
|
## License
|
||||||
|
|
||||||
|
19
metadata.php
19
metadata.php
@ -43,7 +43,7 @@ $aModule = [
|
|||||||
'url' => 'https://www.oxid-esales.com/',
|
'url' => 'https://www.oxid-esales.com/',
|
||||||
'email' => '',
|
'email' => '',
|
||||||
'controllers' => [
|
'controllers' => [
|
||||||
'ith_basic_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class,
|
'oe_captcha_generator' => OxidProfessionalServices\Captcha\Application\Controller\ImageGeneratorController::class,
|
||||||
],
|
],
|
||||||
'extend' => [
|
'extend' => [
|
||||||
OxidEsales\Eshop\Application\Controller\ArticleDetailsController::class => OxidProfessionalServices\Captcha\Application\Controller\DetailsController::class,
|
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,
|
OxidEsales\Eshop\Application\Component\Widget\ArticleDetails::class => OxidProfessionalServices\Captcha\Application\Component\Widget\ArticleDetails::class,
|
||||||
],
|
],
|
||||||
'templates' => [
|
'templates' => [
|
||||||
'oe_captcha.tpl' => 'views/smarty/tpl/oe_captcha.tpl',
|
'oe_captcha.tpl' => 'views/smarty/tpl/include/oe_captcha.tpl',
|
||||||
],
|
],
|
||||||
'blocks' => [
|
'blocks' => [
|
||||||
[
|
[
|
||||||
@ -63,11 +63,6 @@ $aModule = [
|
|||||||
'block' => 'captcha_form',
|
'block' => 'captcha_form',
|
||||||
'file' => 'views/smarty/blocks/oe_captcha_form.tpl',
|
'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',
|
'template' => 'form/privatesales/invite.tpl',
|
||||||
'block' => 'captcha_form',
|
'block' => 'captcha_form',
|
||||||
@ -78,16 +73,6 @@ $aModule = [
|
|||||||
'block' => 'captcha_form',
|
'block' => 'captcha_form',
|
||||||
'file' => 'views/smarty/blocks/oe_captcha_form.tpl',
|
'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' => [
|
'settings' => [
|
||||||
[
|
[
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
[{$smarty.block.parent}]
|
|
||||||
|
|
||||||
[{include file="oe_captcha.tpl"}]
|
|
@ -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()}]" />
|
<input type="hidden" name="c_mach" value="[{$oCaptcha->getHash()}]" />
|
||||||
|
|
||||||
<div class="form-group verify">
|
<div class="form-group verify">
|
@ -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>
|
|
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "form/contact.html.twig" %}
|
||||||
|
|
||||||
|
{% block captcha_form %}
|
||||||
|
{{ parent() }}
|
||||||
|
{% include "@oecaptcha/oe_captcha.html.twig" %}
|
||||||
|
{% endblock %}
|
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "form/pricealarm.html.twig" %}
|
||||||
|
|
||||||
|
{% block captcha_form %}
|
||||||
|
{{ parent() }}
|
||||||
|
{% include "@oecaptcha/oe_captcha.html.twig" %}
|
||||||
|
{% endblock %}
|
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "form/privatesales/invite.html.twig" %}
|
||||||
|
|
||||||
|
{% block captcha_form %}
|
||||||
|
{{ parent() }}
|
||||||
|
{% include "@oecaptcha/oe_captcha.html.twig" %}
|
||||||
|
{% endblock %}
|
26
views/twig/oe_captcha.html.twig
Normal file
26
views/twig/oe_captcha.html.twig
Normal 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>
|
Loading…
Reference in New Issue
Block a user