core23/antispam-bundle

此软件包已被弃用且不再维护。作者建议使用nucleos/antispam-bundle软件包。

此软件包提供了一些基本功能,以减少symfony表单中的垃圾邮件。

此软件包的官方仓库似乎已消失,因此软件包已被冻结。

资助软件包维护!
core23
Opencollective
Ko-Fi
其他

安装数: 13,232

依赖项: 0

建议者: 0

安全性: 0

星级: 52

关注者: 2

分支: 10

开放问题: 7

类型:symfony-bundle

3.1.0 2023-12-05 20:02 UTC

README

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Continuous Integration Code Coverage Type Coverage

此软件包提供了一些基本功能,以减少Symfony中的垃圾邮件。

功能

  • 表单的蜜罐保护:将在您的表单中添加一个额外的“隐藏”字段(即使用CSS使其不可见)。填写此字段的人被视为垃圾邮件机器人。

  • 表单的时间保护:测量表单的显示和提交之间的时间。任何提交表单快于一定秒数的人被视为垃圾邮件机器人。时间戳存储在会话中。

  • Twig的电子邮件地址模糊化过滤器:为了防止垃圾邮件收集机器人检测您的电子邮件地址,它们被例如用[AT]替换@等方式模糊化。该过滤器将自动找到电子邮件地址,因此您可以将它应用于整个文本。

安装

打开命令行,进入您的项目目录,并执行以下命令以下载此软件包的最新稳定版本

composer require nucleos/antispam-bundle

启用软件包

在旧版本的Symfony中,您需要手动启用它

// config/bundles.php

return [
    // ...
    Nucleos\AntiSpamBundle\NucleosAntiSpamBundle::class => ['all' => true],
];

使用

基于表单的保护

在控制器中

$this->createForm(CustomFormType:class, null, [
    // Time protection
    'antispam_time'     => true,
    'antispam_time_min' => 10, // seconds
    'antispam_time_max' => 60,

    // Honeypot protection
    'antispam_honeypot'       => true,
    'antispam_honeypot_class' => 'hide-me',
    'antispam_honeypot_field' => 'email-repeat',
])

在表单类中

class MyType extends AbstractType
{
    // ...

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            // ...
            'antispam_time'     => true,
            'antispam_time_min' => 10,
            // same as above
        ]);
    }
}

Twig电子邮件地址模糊化

Twig过滤器antispam@替换为例如[AT]

{# Replace plain text #}
{{ text|antispam }}

{# Replace rich text mails #}
{{ htmlText|antispam(true) }}

如果您想对编码的电子邮件地址进行JavaScript解码,应使用AntiSpam.js

document.addEventListener('DOMContentLoaded', () => {
  new AntiSpam('.custom_class');
});

建议使用webpack / webpack-encore将JavaScript库包含在您的页面中。此文件位于assets文件夹中。

配置软件包

创建一个名为nucleos_antispam.yaml的配置文件

# config/packages/nucleos_antispam.yaml

nucleos_antispam:
    # Twig mail filter
    twig:
        mail:
            css_class: 'custom_class'
            at_text:   [ '[AT]', '(AT)', '[ÄT]' ]
            dot_text:  [ '[DOT]', '(DOT)', '[.]' ]

    # Time protection
    time:
        min: 5
        max: 3600
        global: true # This will add antispam to all forms

    # Honeypot protection
    honeypot:
        field: 'email_address'
        class: 'hidden'
        global: false
        provider: 'nucleos_antispam.provider.session'

when@test:
    nucleos_antispam:
        time:
            # This will allow you to submit forms in your tests without having to fake the wait
            min: 0

许可证

此软件包受MIT许可证的约束。