定制 sithous/antispam-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sithous/antispam-bundle

Composer 安装命令:

composer require sithous/antispam-bundle

包简介

Provides Anti-Spam capabilities to Symfony in an easy to use package..

README 文档

README

Provides Anti-Spam capabilities to Symfony in an easy to use package.

Check us out on packagist! https://packagist.org/packages/sithous/antispam-bundle

We recommend using fixtures to load in your SithousAntiSpamTypes so they can be moved to the production server or vice versa.

Requirements

  • => PHP 5.3.2
  • => Symfony 2.3
  • => Symfony Console 2.3
  • Doctrine

Installation

Step 1: Add to composer

add the bundle to your root composer.json file under the require section

"sithous/antispam-bundle": "1.0.*"

After adding that run composer to fetch the package into your vendors folder

php composer.phar update

Step 2: Enable the bundle

Enable the bundle by adding the following to the app/config/appKernel.php

new Sithous\AntiSpamBundle\SithousAntiSpamBundle(),

Step 3: Update database

First, verify the SQL to make sure nothing will break

php app/console doctrine:schema:update --dump-sql

If everything looks good, execute the schema update.

php app/console doctrine:schema:update --force

Configuration

By default the AntiSpamBundle runs garbage collection every time a verify() call is made. You can change this to run in a cron every couple minutes by setting active_gc to true.

# app/config/config.yml
sithous_anti_spam:
    active_gc: true   # set to false to use cron garbage collection

If you want to use cron garbage collection you will need to make a cron job run the following command:

php app/console sithous:antispambundle:gc

Example Usage

A good example is if you want users to be able to vote on something but only want the user and IP of user to vote once a day. To do this you would first generate the SithousAntiSpamType using the following command:

$ 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"

Now in your controller function you will run the verify command before submitting the vote

    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()
            ));
        }
    }

If you later want to remove a SithousAntiSpamType run the following command:

$ php app/console sithous:antispam:delete
Enter the SithousAntiSpamType ID to delete: vote_protection
Successfully removed SithousAntiSpamType "vote_protection"

统计信息

  • 总下载量: 619
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固