Commit 5d2e182f authored by Tino Goratsch's avatar Tino Goratsch

use the first parts of new captcha infrastructure

parent 9d33e749
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
......
......@@ -8,12 +8,9 @@ namespace ACP3\Modules\ACP3\Captcha\Event\Listener;
use ACP3\Core\ACL;
use ACP3\Core\View\Event\TemplateEvent;
use ACP3\Modules\ACP3\Captcha\Helpers;
use ACP3\Modules\ACP3\Captcha\Extension\CaptchaExtensionInterface;
use ACP3\Modules\ACP3\Captcha\Extension\CaptchaFactory;
/**
* Class OnFormAfterListener
* @package ACP3\Modules\ACP3\Captcha\Event\Listener
*/
class OnDisplayCaptchaListener
{
/**
......@@ -21,20 +18,20 @@ class OnDisplayCaptchaListener
*/
protected $acl;
/**
* @var \ACP3\Modules\ACP3\Captcha\Helpers
* @var CaptchaFactory
*/
protected $captchaHelper;
private $captchaFactory;
/**
* OnAfterFormListener constructor.
*
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Modules\ACP3\Captcha\Helpers $captchaHelper
* @param \ACP3\Core\ACL $acl
* @param CaptchaFactory $captchaFactory
*/
public function __construct(ACL $acl, Helpers $captchaHelper)
public function __construct(ACL $acl, CaptchaFactory $captchaFactory)
{
$this->acl = $acl;
$this->captchaHelper = $captchaHelper;
$this->captchaFactory = $captchaFactory;
}
/**
......@@ -44,9 +41,11 @@ class OnDisplayCaptchaListener
{
if ($this->acl->hasPermission('frontend/captcha/index/image') === true) {
$arguments = $templateEvent->getParameters();
echo $this->captchaHelper->captcha(
isset($arguments['length']) ? $arguments['length'] : Helpers::CAPTCHA_DEFAULT_LENGTH,
isset($arguments['input_id']) ? $arguments['input_id'] : Helpers::CAPTCHA_DEFAULT_INPUT_ID,
$captcha = $this->captchaFactory->create();
echo $captcha->getCaptcha(
isset($arguments['length']) ? $arguments['length'] : CaptchaExtensionInterface::CAPTCHA_DEFAULT_LENGTH,
isset($arguments['input_id']) ? $arguments['input_id'] : CaptchaExtensionInterface::CAPTCHA_DEFAULT_INPUT_ID,
isset($arguments['input_only']) ? $arguments['input_only'] : false,
isset($arguments['path']) ? $arguments['path'] : ''
);
......
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Captcha\Extension;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\Captcha\Installer\Schema;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CaptchaFactory
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @var SettingsInterface
*/
private $settings;
/**
* CaptchaFactory constructor.
* @param SettingsInterface $settings
* @param ContainerInterface $container
*/
public function __construct(SettingsInterface $settings, ContainerInterface $container)
{
$this->container = $container;
$this->settings = $settings;
}
/**
* @return CaptchaExtensionInterface
*/
public function create()
{
$settings = $this->settings->getSettings(Schema::MODULE_NAME);
if ($this->container->has($settings['captcha'])) {
/** @var CaptchaExtensionInterface $service */
$service = $this->container->get($settings['captcha']);
return $service;
}
throw new \InvalidArgumentException(
sprintf('Can not find the captcha extension with the name "%s".', $settings['captcha'])
);
}
}
......@@ -3,7 +3,7 @@ services:
class: ACP3\Modules\ACP3\Captcha\Event\Listener\OnDisplayCaptchaListener
arguments:
- '@core.acl'
- '@captcha.helpers'
- '@cpatcha.extension.captcha_factory'
tags:
- { name: core.eventListener, event: captcha.event.display_captcha, method: onDisplayCaptcha }
......
......@@ -11,3 +11,9 @@ services:
- '@users.model.user_model'
tags:
- { name: 'captcha.extension.captcha' }
cpatcha.extension.captcha_factory:
class: ACP3\Modules\ACP3\Captcha\Extension\CaptchaFactory
arguments:
- '@core.config'
- '@service_container'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment