WIP: reCaptcha -> hCaptcha #6

Draft
skobkin wants to merge 1 commit from feature_hcaptcha into master
15 changed files with 209 additions and 191 deletions
Showing only changes of commit 1c8755bf19 - Show all commits

15
.env
View file

@ -31,14 +31,7 @@ MAILER_DSN=smtp://localhost
MAILER_FROM=no-reply@magnetico-web.tld MAILER_FROM=no-reply@magnetico-web.tld
###< symfony/mailer ### ###< symfony/mailer ###
###> google/recaptcha ### ###> meteo-concept/hcaptcha-bundle ###
# To use Google Recaptcha, you must register a site on Recaptcha's admin panel: HCAPTCHA_SITE=123456789
# https://www.google.com/recaptcha/admin HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000
#GOOGLE_RECAPTCHA_SITE_KEY= ###< meteo-concept/hcaptcha-bundle ###
#GOOGLE_RECAPTCHA_SECRET=
###< google/recaptcha ###
###> excelwebzone/recaptcha-bundle ###
EWZ_RECAPTCHA_SITE_KEY=
EWZ_RECAPTCHA_SECRET=
###< excelwebzone/recaptcha-bundle ###

View file

@ -24,7 +24,8 @@
"doctrine/doctrine-bundle": "^2", "doctrine/doctrine-bundle": "^2",
"doctrine/doctrine-migrations-bundle": "^2", "doctrine/doctrine-migrations-bundle": "^2",
"doctrine/orm": "^2", "doctrine/orm": "^2",
"excelwebzone/recaptcha-bundle": "^1.5", "meteo-concept/hcaptcha-bundle": "^3.2",
"nyholm/psr7": "^1.5",
"pagerfanta/doctrine-orm-adapter": "^3.6", "pagerfanta/doctrine-orm-adapter": "^3.6",
"pagerfanta/twig": "^3.6", "pagerfanta/twig": "^3.6",
"phpdocumentor/reflection-docblock": "^5.3", "phpdocumentor/reflection-docblock": "^5.3",
@ -39,7 +40,7 @@
"symfony/flex": "^1.0", "symfony/flex": "^1.0",
"symfony/form": "^5.4", "symfony/form": "^5.4",
"symfony/framework-bundle": "^5.4", "symfony/framework-bundle": "^5.4",
"symfony/http-client": "^5.4", "symfony/http-client": "5.4.*",
"symfony/mailer": "^5.4", "symfony/mailer": "^5.4",
"symfony/monolog-bundle": "^3.3", "symfony/monolog-bundle": "^3.3",
"symfony/property-access": "^5.4", "symfony/property-access": "^5.4",

254
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bfa726a8284bf45a7ccbbb6600e02128", "content-hash": "a8bee2535da266f0feee500c5adb71a1",
"packages": [ "packages": [
{ {
"name": "babdev/pagerfanta-bundle", "name": "babdev/pagerfanta-bundle",
@ -1816,66 +1816,6 @@
], ],
"time": "2022-06-18T20:57:19+00:00" "time": "2022-06-18T20:57:19+00:00"
}, },
{
"name": "excelwebzone/recaptcha-bundle",
"version": "v1.5.35",
"source": {
"type": "git",
"url": "https://github.com/excelwebzone/EWZRecaptchaBundle.git",
"reference": "8dad97a2017dcb650c18ff17ff1b8c54c1847dac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/excelwebzone/EWZRecaptchaBundle/zipball/8dad97a2017dcb650c18ff17ff1b8c54c1847dac",
"reference": "8dad97a2017dcb650c18ff17ff1b8c54c1847dac",
"shasum": ""
},
"require": {
"google/recaptcha": "^1.1",
"php": "^7.1 || ^8.0",
"symfony/form": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/validator": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"twig/twig": "^1.40 || ^2.9 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7 || ^8 || ^9.5"
},
"type": "symfony-bundle",
"extra": {
"symfony": {
"allow-contrib": "true"
}
},
"autoload": {
"psr-4": {
"EWZ\\Bundle\\RecaptchaBundle\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael H. Arieli",
"email": "excelwebzone@gmail.com",
"homepage": "http://excelwebzone.com/"
}
],
"description": "This bundle provides easy reCAPTCHA form field integration",
"homepage": "https://github.com/excelwebzone/EWZRecaptchaBundle",
"keywords": [
"recaptcha"
],
"support": {
"issues": "https://github.com/excelwebzone/EWZRecaptchaBundle/issues",
"source": "https://github.com/excelwebzone/EWZRecaptchaBundle/tree/v1.5.35"
},
"time": "2022-04-22T16:52:19+00:00"
},
{ {
"name": "friendsofphp/proxy-manager-lts", "name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.12", "version": "v1.0.12",
@ -1958,58 +1898,6 @@
], ],
"time": "2022-05-05T09:31:05+00:00" "time": "2022-05-05T09:31:05+00:00"
}, },
{
"name": "google/recaptcha",
"version": "1.2.4",
"source": {
"type": "git",
"url": "https://github.com/google/recaptcha.git",
"reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/recaptcha/zipball/614f25a9038be4f3f2da7cbfd778dc5b357d2419",
"reference": "614f25a9038be4f3f2da7cbfd778dc5b357d2419",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.2.20|^2.15",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7.5.11"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"psr-4": {
"ReCaptcha\\": "src/ReCaptcha"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Client library for reCAPTCHA, a free service that protects websites from spam and abuse.",
"homepage": "https://www.google.com/recaptcha/",
"keywords": [
"Abuse",
"captcha",
"recaptcha",
"spam"
],
"support": {
"forum": "https://groups.google.com/forum/#!forum/recaptcha",
"issues": "https://github.com/google/recaptcha/issues",
"source": "https://github.com/google/recaptcha"
},
"time": "2020-03-31T17:50:54+00:00"
},
{ {
"name": "guzzlehttp/promises", "name": "guzzlehttp/promises",
"version": "1.5.1", "version": "1.5.1",
@ -2392,6 +2280,69 @@
], ],
"time": "2022-06-06T11:26:02+00:00" "time": "2022-06-06T11:26:02+00:00"
}, },
{
"name": "meteo-concept/hcaptcha-bundle",
"version": "v3.2.1",
"source": {
"type": "git",
"url": "https://github.com/Meteo-Concept/hcaptcha-bundle.git",
"reference": "7d552dde4453722f5aec092ab21a9c4ed2e92fae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Meteo-Concept/hcaptcha-bundle/zipball/7d552dde4453722f5aec092ab21a9c4ed2e92fae",
"reference": "7d552dde4453722f5aec092ab21a9c4ed2e92fae",
"shasum": ""
},
"require": {
"php": "^7.4|^8.0",
"psr/http-client": "^1.0",
"psr/http-client-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"symfony/config": "~5.4|~6.0",
"symfony/form": "~5.4|~6.0",
"symfony/twig-bridge": "~5.4|~6.0",
"symfony/validator": "~5.4|~6.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"nyholm/psr7": "^1.3",
"nyholm/symfony-bundle-test": "1.x-dev",
"php-http/mock-client": "^1.5",
"symfony/browser-kit": "^5.3|^6.0",
"symfony/css-selector": "^5.3|^6.0",
"symfony/framework-bundle": "^5.3|^6.0",
"symfony/panther": "^1.1|^2.0",
"symfony/phpunit-bridge": "^5.3|^6.0",
"symfony/twig-bundle": "^5.3|^6.0"
},
"suggest": {
"symfony/http-client": "A Symfony component that implements PSR-18 HTTP client interface"
},
"type": "symfony-bundle",
"autoload": {
"psr-4": {
"MeteoConcept\\HCaptchaBundle\\": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Laurent Georget",
"email": "laurent.georget@meteo-concept.fr"
}
],
"description": "A Symfony bundle to use hCaptcha in forms",
"support": {
"issues": "https://github.com/Meteo-Concept/hcaptcha-bundle/issues",
"source": "https://github.com/Meteo-Concept/hcaptcha-bundle/tree/v3.2.1"
},
"time": "2022-01-17T07:46:02+00:00"
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "2.7.0", "version": "2.7.0",
@ -2496,6 +2447,83 @@
], ],
"time": "2022-06-09T08:59:12+00:00" "time": "2022-06-09T08:59:12+00:00"
}, },
{
"name": "nyholm/psr7",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/Nyholm/psr7.git",
"reference": "f734364e38a876a23be4d906a2a089e1315be18a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a",
"reference": "f734364e38a876a23be4d906a2a089e1315be18a",
"shasum": ""
},
"require": {
"php": ">=7.1",
"php-http/message-factory": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"http-interop/http-factory-tests": "^0.9",
"php-http/psr7-integration-tests": "^1.0",
"phpunit/phpunit": "^7.5 || 8.5 || 9.4",
"symfony/error-handler": "^4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"Nyholm\\Psr7\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com"
},
{
"name": "Martijn van der Ven",
"email": "martijn@vanderven.se"
}
],
"description": "A fast PHP7 implementation of PSR-7",
"homepage": "https://tnyholm.se",
"keywords": [
"psr-17",
"psr-7"
],
"support": {
"issues": "https://github.com/Nyholm/psr7/issues",
"source": "https://github.com/Nyholm/psr7/tree/1.5.1"
},
"funding": [
{
"url": "https://github.com/Zegnat",
"type": "github"
},
{
"url": "https://github.com/nyholm",
"type": "github"
}
],
"time": "2022-06-22T07:13:36+00:00"
},
{ {
"name": "pagerfanta/core", "name": "pagerfanta/core",
"version": "v3.6.1", "version": "v3.6.1",

View file

@ -1,5 +1,4 @@
<?php <?php
declare(strict_types=1);
return [ return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
@ -12,6 +11,6 @@ return [
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['all' => true], Sentry\SentryBundle\SentryBundle::class => ['all' => true],
EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle::class => ['all' => true],
Baldinof\RoadRunnerBundle\BaldinofRoadRunnerBundle::class => ['all' => true], Baldinof\RoadRunnerBundle\BaldinofRoadRunnerBundle::class => ['all' => true],
MeteoConcept\HCaptchaBundle\MeteoConceptHCaptchaBundle::class => ['all' => true],
]; ];

View file

@ -1,2 +0,0 @@
ewz_recaptcha:
enabled: false

View file

@ -1,4 +0,0 @@
# See https://github.com/excelwebzone/EWZRecaptchaBundle for full configuration
ewz_recaptcha:
public_key: '%env(EWZ_RECAPTCHA_SITE_KEY)%'
private_key: '%env(EWZ_RECAPTCHA_SECRET)%'

View file

@ -1,21 +0,0 @@
#services:
#
# # Inject this service in your controllers/services to verify a submitted captcha.
# ReCaptcha\ReCaptcha:
# arguments:
# $secret: '%env(GOOGLE_RECAPTCHA_SECRET)%'
# $requestMethod: '@ReCaptcha\RequestMethod'
#
# # Curl is set here as default transport to communicate with Google servers.
# # If you do not have php-curl extension, you can change for a socket or a plain POST request.
# # Check out the repository for all other request methods:
# # https://github.com/google/recaptcha/tree/master/src/ReCaptcha/RequestMethod
# ReCaptcha\RequestMethod: '@ReCaptcha\RequestMethod\CurlPost'
# ReCaptcha\RequestMethod\CurlPost: null
# ReCaptcha\RequestMethod\Curl: null
#
## Uncomment this line if you want to inject the site key to all your Twig templates.
## You can also inject the "google_recaptcha_site_key" container parameter to your controllers.
##twig:
## globals:
## google_recaptcha_site_key: '%google_recaptcha_site_key%'

View file

@ -0,0 +1,4 @@
meteo_concept_h_captcha:
hcaptcha:
site_key: '%env(resolve:HCAPTCHA_SITE)%'
secret: '%env(resolve:HCAPTCHA_SECRET)%'

View file

@ -0,0 +1,21 @@
services:
# Register nyholm/psr7 services for autowiring with PSR-17 (HTTP factories)
Psr\Http\Message\RequestFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\ResponseFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\ServerRequestFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\StreamFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\UploadedFileFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\UriFactoryInterface: '@nyholm.psr7.psr17_factory'
# Register nyholm/psr7 services for autowiring with HTTPlug factories
Http\Message\MessageFactory: '@nyholm.psr7.httplug_factory'
Http\Message\RequestFactory: '@nyholm.psr7.httplug_factory'
Http\Message\ResponseFactory: '@nyholm.psr7.httplug_factory'
Http\Message\StreamFactory: '@nyholm.psr7.httplug_factory'
Http\Message\UriFactory: '@nyholm.psr7.httplug_factory'
nyholm.psr7.psr17_factory:
class: Nyholm\Psr7\Factory\Psr17Factory
nyholm.psr7.httplug_factory:
class: Nyholm\Psr7\Factory\HttplugFactory

View file

@ -2,4 +2,6 @@ twig:
paths: ['%kernel.project_dir%/templates'] paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%' debug: '%kernel.debug%'
strict_variables: '%kernel.debug%' strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig'] form_themes:
- 'bootstrap_4_layout.html.twig'
- '@MeteoConceptHCaptcha/hcaptcha_form.html.twig'

View file

@ -59,3 +59,8 @@ services:
class: App\Pager\View\TwitterBootstrap4PagelessView class: App\Pager\View\TwitterBootstrap4PagelessView
public: false public: false
tags: [{ name: pagerfanta.view, alias: twitter_bootstrap4_pageless }] tags: [{ name: pagerfanta.view, alias: twitter_bootstrap4_pageless }]
# for hCaptcha
# https://github.com/Meteo-Concept/hcaptcha-bundle#configuration
Psr\Http\Client\ClientInterface:
class: Symfony\Component\HttpClient\Psr18Client

View file

@ -51,7 +51,7 @@ class UserController extends AbstractController
]); ]);
} }
public function requestReset(Request $request, EntityManagerInterface $em, PasswordResetManager $manager): Response public function requestReset(Request $request, PasswordResetManager $manager): Response
{ {
$formData = new PasswordResetRequestData(); $formData = new PasswordResetRequestData();
$form = $this->createResetRequestForm($formData); $form = $this->createResetRequestForm($formData);

View file

@ -14,11 +14,4 @@ class PasswordResetRequestData
* @Assert\NotBlank() * @Assert\NotBlank()
*/ */
public $email; public $email;
/**
* @var string
*
* @ReCaptcha\IsTrue
*/
public $recaptcha;
} }

View file

@ -4,7 +4,7 @@ namespace App\Form;
use App\Form\Data\PasswordResetRequestData; use App\Form\Data\PasswordResetRequestData;
use Symfony\Component\Form\{AbstractType, Extension\Core\Type\EmailType, FormBuilderInterface}; use Symfony\Component\Form\{AbstractType, Extension\Core\Type\EmailType, FormBuilderInterface};
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType; use MeteoConcept\HCaptchaBundle\Form\HCaptchaType;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
class PasswordResetRequestType extends AbstractType class PasswordResetRequestType extends AbstractType
@ -13,7 +13,7 @@ class PasswordResetRequestType extends AbstractType
{ {
$builder $builder
->add('email', EmailType::class, ['required' => true]) ->add('email', EmailType::class, ['required' => true])
->add('recaptcha', EWZRecaptchaType::class) ->add('captcha', HCaptchaType::class)
; ;
} }

View file

@ -86,31 +86,6 @@
"egulias/email-validator": { "egulias/email-validator": {
"version": "2.1.14" "version": "2.1.14"
}, },
"excelwebzone/recaptcha-bundle": {
"version": "1.5",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "master",
"version": "1.5",
"ref": "fd4da7bc71749db65bc83abf5d164bfa9c839cf4"
},
"files": [
"config/packages/dev/ewz_recaptcha.yaml",
"config/packages/ewz_recaptcha.yaml"
]
},
"google/recaptcha": {
"version": "1.1",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "master",
"version": "1.1",
"ref": "d087df3e087f50da3955f2def05079380da5894b"
},
"files": [
"config/packages/google_recaptcha.yaml"
]
},
"guzzlehttp/promises": { "guzzlehttp/promises": {
"version": "v1.3.1" "version": "v1.3.1"
}, },
@ -129,9 +104,33 @@
"laminas/laminas-zendframework-bridge": { "laminas/laminas-zendframework-bridge": {
"version": "1.0.1" "version": "1.0.1"
}, },
"meteo-concept/hcaptcha-bundle": {
"version": "3.2",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "1.0",
"ref": "e94efaa6cd60c87dc9cc6de56b333a1754187d1e"
},
"files": [
"config/packages/meteo_concept_h_captcha.yaml"
]
},
"monolog/monolog": { "monolog/monolog": {
"version": "1.23.0" "version": "1.23.0"
}, },
"nyholm/psr7": {
"version": "1.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "0cd4d2d0e7f646fda75f9944f747a56e6ed13d4c"
},
"files": [
"config/packages/nyholm_psr7.yaml"
]
},
"ocramius/package-versions": { "ocramius/package-versions": {
"version": "1.3.0" "version": "1.3.0"
}, },