sithous / antispam-bundle
通过一个易于使用的包为Symfony提供反垃圾邮件功能。
1.0.3
2017-12-16 09:21 UTC
Requires
- php: >=5.3.2
- symfony/console: >=2.3
- symfony/framework-bundle: >=2.3
This package is auto-updated.
Last update: 2024-09-13 05:27:53 UTC
README
通过一个易于使用的包为Symfony提供反垃圾邮件功能。
在Packagist上查看我们! https://packagist.org.cn/packages/sithous/antispam-bundle
我们建议使用固定值来加载您的 SithousAntiSpamTypes
,以便它们可以在生产服务器或反之亦然之间移动。
需求
- => PHP 5.3.2
- => Symfony 2.3
- => Symfony Console 2.3
- Doctrine
安装
步骤 1:添加到composer
在根 composer.json 文件下的 require
部分添加此包
"sithous/antispam-bundle": "1.0.*"
添加后运行composer以将包获取到您的 vendors 文件夹
php composer.phar update
步骤 2:启用包
通过将以下内容添加到 app/config/appKernel.php
中来启用包
new Sithous\AntiSpamBundle\SithousAntiSpamBundle(),
步骤 3:更新数据库
首先,验证SQL以确保不会破坏任何内容
php app/console doctrine:schema:update --dump-sql
如果一切看起来都很好,执行模式更新。
php app/console doctrine:schema:update --force
配置
默认情况下,AntiSpamBundle在每次调用verify()时都会运行垃圾收集。您可以通过将active_gc
设置为true将其更改为每几分钟运行一次cron。
# app/config/config.yml
sithous_anti_spam:
active_gc: true # set to false to use cron garbage collection
如果您想使用cron垃圾收集,需要创建一个cron作业来运行以下命令
php app/console sithous:antispambundle:gc
示例用法
一个好的例子是,如果您希望用户能够对某些内容进行投票,但只想让用户和用户的IP每天投票一次。为此,您首先使用以下命令生成SithousAntiSpamType:
$ php app/console sithous:antispam:generate
Please enter the ID for this type: vote_protection
Track IP [Y/N]? Y
Track User [Y/N]? Y
Max Time to track action (seconds): 86400
Max Calls that can happin in MaxTime: 1
ID: vote_protection
trackIp: true
trackUser: true
maxTime: 86400 seconds
maxCalls: 1
Is the above information correct [Y/N]? Y
Successfully added SithousAntiSpamType "vote_protection"
现在,在您的控制器函数中,在提交投票之前运行verify命令
public function submitVoteAction(Request $request)
{
// somewhere in your code...
$spamCheck = $this->get('sithous.antispam');
if(!$spamCheck->setType('vote_protection')->verify())
{
return new JsonResponse(array(
'result' => 'error',
'message' => $spamCheck->getErrorMessage()
));
}
}
如果您以后想删除SithousAntiSpamType,请运行以下命令
$ php app/console sithous:antispam:delete
Enter the SithousAntiSpamType ID to delete: vote_protection
Successfully removed SithousAntiSpamType "vote_protection"