diff --git a/README.md b/README.md index 41a688f..2145cdd 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ This bundle provides easy [friendlycaptcha.com](https://www.friendlycaptcha.com) This is a fork of the [cors][https://github.com/cors-gmbh/friendly-captcha-bundle] bundle, that does not seems to be maintened, [see this PR for details][https://github.com/cors-gmbh/friendly-captcha-bundle/pull/3] +The main branch works with the v2 API, see https://developer.friendlycaptcha.com/docs/v2/guides/upgrading-from-v1/backend-integration for migration instruction or use the main_v1 / v1.x version of the bundle. + ## Installation ### Step 1: Use composer and enable Bundle @@ -18,18 +20,17 @@ php composer.phar require elma/friendly-captcha-bundle ``` Now, Composer will automatically download all required files, and install them -for you. All that is left to do is to update your ``AppKernel.php`` file, and +for you. All that is left to do is to update your ``bundles.php`` file, and register the new bundle: ```php ['all' => true], + //... + ]; ``` ### Step2: Configure the bundle's @@ -37,7 +38,7 @@ $bundles = array( ```yaml cors_friendly_captcha: sitekey: here_is_your_sitekey - secret: here_is_your_secret + secret: here_is_your_api_key use_eu_endpoints: true|false ``` @@ -45,10 +46,10 @@ cors_friendly_captcha: ```yaml cors_friendly_captcha: - puzzle: + puzzle: endpoint: https://api.friendlycaptcha.com/api/v1/puzzle eu_endpoint: https://eu-api.friendlycaptcha.eu/api/v1/puzzle - validation: - endpoint: https://api.friendlycaptcha.com/api/v1/siteverify - eu_endpoint: https://eu-api.friendlycaptcha.eu/api/v1/siteverify -``` + validation: + endpoint: https://global.frcapi.com/api/v2/captcha/siteverify + eu_endpoint: https://eu.frcapi.com/api/v2/captcha/siteverify +``` \ No newline at end of file diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..1041e7e --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,15 @@ +UPGRADE FROM 1.x to 2.x +=== + +## Introduction + +The v2 of this bundle is based upon the Friendly Captcha v2 version: https://developer.friendlycaptcha.com/docs/v2 + +#### Breaking changes + +* Removed the form options: `lang`, `callback`, `puzzle-endpoint` and `lang` . + +#### Requirements + +* To activate the v2 a new api key is necessary: https://developer.friendlycaptcha.com/docs/v2/guides/upgrading-from-v1/backend-integration#3-replace-the-secret-field +* For a v2 migration front guide: https://developer.friendlycaptcha.com/docs/v2/guides/upgrading-from-v1/script diff --git a/composer.json b/composer.json index 68ec69a..a5dff9b 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ }, "extra": { "branch-alias": { - "dev-main": "1.0-dev" + "dev-main": "2.0-dev" }, "symfony": { "allow-contrib": "true" diff --git a/src/DependencyInjection/CORSFriendlyCaptchaExtension.php b/src/DependencyInjection/CORSFriendlyCaptchaExtension.php index d49b17e..bac8ba3 100644 --- a/src/DependencyInjection/CORSFriendlyCaptchaExtension.php +++ b/src/DependencyInjection/CORSFriendlyCaptchaExtension.php @@ -16,11 +16,12 @@ public function load(array $configs, ContainerBuilder $container): void $configs = $this->processConfiguration($this->getConfiguration([], $container), $configs); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - if ($configs['use_eu_endpoints']) { - $puzzleEndpoint = $configs['puzzle']['eu_endpoint']; - $verificationEndpoint = $configs['validation']['eu_endpoint']; - } - else { + $container->setParameter('cors.friendly_captcha.use_eu_endpoints', true); + $puzzleEndpoint = $configs['puzzle']['eu_endpoint']; + $verificationEndpoint = $configs['validation']['eu_endpoint']; + + if (isset($configs['use_eu_endpoints']) && $configs['use_eu_endpoints'] == false){ + $container->setParameter('cors.friendly_captcha.use_eu_endpoints', false); $puzzleEndpoint = $configs['puzzle']['endpoint']; $verificationEndpoint = $configs['validation']['endpoint']; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 34b579b..39c83b4 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -30,8 +30,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->arrayNode('validation') ->addDefaultsIfNotSet() ->children() - ->scalarNode('endpoint')->defaultValue('https://api.friendlycaptcha.com/api/v1/siteverify')->end() - ->scalarNode('eu_endpoint')->defaultValue('https://eu-api.friendlycaptcha.eu/api/v1/siteverify')->end() + ->scalarNode('endpoint')->defaultValue('https://global.frcapi.com/api/v2/captcha/siteverify')->end() + ->scalarNode('eu_endpoint')->defaultValue('https://eu.frcapi.com/api/v2/captcha/siteverify')->end() ->end() ->end() ->end(); diff --git a/src/Form/Type/FriendlyCaptchaType.php b/src/Form/Type/FriendlyCaptchaType.php index 4682be0..d77dd12 100644 --- a/src/Form/Type/FriendlyCaptchaType.php +++ b/src/Form/Type/FriendlyCaptchaType.php @@ -13,13 +13,13 @@ final class FriendlyCaptchaType extends AbstractType { - protected $sitekey; - protected $endpoint; + protected string $sitekey; + protected bool $useEuEndpoints; - public function __construct(string $sitekey, string $endpoint) + public function __construct(string $sitekey, bool $useEuEndpoints) { $this->sitekey = $sitekey; - $this->endpoint = $endpoint; + $this->useEuEndpoints = $useEuEndpoints; } public function getParent() @@ -30,12 +30,13 @@ public function getParent() public function buildView(FormView $view, FormInterface $form, array $options) { $fcValues = array_filter([ - 'puzzle-endpoint' => $this->endpoint, - 'lang' => $options['lang'] ?? null, - 'start' => $options['start'] ?? null, - 'callback' => $options['callback'] ?? null, + 'start' => $options['start'] ?? null ]); + if ($this->useEuEndpoints == true) { + $fcValues['api-endpoint'] = 'eu'; + } + $view->vars['sitekey'] = $this->sitekey; $view->vars['friendly_captcha'] = $fcValues; } @@ -43,9 +44,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'lang' => null, 'start' => 'focus', - 'callback' => null, 'constraints' => [new FriendlyCaptchaValid()] ]); diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index d29ede2..9e532f3 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -12,6 +12,6 @@ services: CORS\Bundle\FriendlyCaptchaBundle\Form\Type\FriendlyCaptchaType: arguments: - '%cors.friendly_captcha.sitekey%' - - '%cors.friendly_captcha.endpoint.puzzle%' + - '%cors.friendly_captcha.use_eu_endpoints%' tags: - { name: form.type } \ No newline at end of file diff --git a/src/Resources/views/friendlycaptcha.html.twig b/src/Resources/views/friendlycaptcha.html.twig index 705ff55..8780805 100644 --- a/src/Resources/views/friendlycaptcha.html.twig +++ b/src/Resources/views/friendlycaptcha.html.twig @@ -1,7 +1,7 @@ {%- block cors_friendly_catcha_type_row -%}