almaviacx/captchetatbundle

将 CaptchEtat 添加到表单

dev-feat-captchetat-bundle 2024-07-16 08:25 UTC

This package is auto-updated.

Last update: 2024-09-16 09:01:53 UTC


README

此存储库是我们所说的“子树分割”:主存储库中一个目录的只读副本。Composer 使用它允许开发者依赖于特定的捆绑包。

如果您想报告或贡献,请改为在主存储库上打开问题: https://github.com/Novactive/Nova-eZPlatform-Bundles

文档可通过此存储库中的 .md 文件获得,但也在此打包: https://novactive.github.io/Nova-eZPlatform-Bundles/master/2FABundle/README.md.html

此捆绑包提供了一个表单类型,可在您的网站上使用 CaptchEtat(《https://api.gouv.fr/les-api/api-captchetat》)

安装

需求

  • Ibexa 4
  • PHP 7.4 || 8.0

使用 Composer

将库添加到您的 composer.json 中,运行 composer require almaviacx/captchetatbundle 以更新依赖项。

注册捆绑包

然后,将捆绑包注入到您的应用程序的 config\bundles.php 中。

    return [
        // ...
        AlmaviaCX\Bundle\CaptchEtatBundle\AlmaviaCXCaptchEtatBundle::class => [ 'all'=> true ],
    ];

添加路由

确保您将此路由添加到您的路由中

# config/routes.yaml

captchetat_routes:
    resource: '@AlmaviaCXCaptchEtatBundle/Resources/config/routes.yaml'

无障碍性

为了无障碍性,您可能想将以下脚本添加到您的 JS 中

import CaptchaEtat from '../public/bundles/almaviacxcaptchetat/js/captchetat-widget'
CaptchaEtat.init()

配置

配置可以通过以下环境变量完成

CAPTCHETAT_API_URL="https://sandbox-api.piste.gouv.fr"
CAPTCHETAT_OAUTH_URL="https://sandbox-oauth.piste.gouv.fr"
CAPTCHETAT_OAUTH_CLIENT_ID=~
CAPTCHETAT_OAUTH_CLIENT_SECRET=~
CAPTCHETAT_TIMEOUT="2.5"

根据您使用的是“沙盒”(默认)还是“生产”环境,您可能想更改 URL 到

CAPTCHETAT_API_URL="https://api.piste.gouv.fr"
CAPTCHETAT_OAUTH_URL="https://oauth.piste.gouv.fr"

将验证码添加到您的表单

$builder->add(
    'captcha', CaptchEtatType::class, 
    [
        'label' => 'customform.show.captcha',
    ]
);

表单构建器表单

您可以通过激活以下服务装饰器自动将验证码添加到表单构建器表单

AlmaviaCX\Bundle\CaptchEtat\FormBuilder\FieldType\Field\Mapper\ButtonFieldMapperDecorator:
    decorates: Ibexa\FormBuilder\FieldType\Field\Mapper\ButtonFieldMapper
    arguments:
        $buttonFieldMapper: '@.inner'