deceze / CakePHP-RequestThrottler-Component

A component for CakePHP to throttle user activity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RequestThrottlerComponent for CakePHP

The RequestThrottlerComponent throttles user actions to a defined number of actions per defined period of time. Upon reaching this limit, the user will need to verify his humanness by solving a Captcha.

Requirements

  • CakeDC recaptcha plugin (https://github.com/CakeDC/recaptcha)
  • An action and corresponding view that display a Captcha, by default UsersController::captcha
  • Assumes standard AuthComponent setup and requires a working session
  • PHP 5+

TODO

  • Plugin-ize, bundling UsersController::captcha action and view
  • Different actions upon reaching limit
  • Different time calculation algorithms
  • Make all options configurable from the controller and/or beforeFilter

Usage

Include in controller with settings array of actions to protect:

public $components = array('RequestThrottler' => array('edit', 'add'));

Example UsersController::captcha action and view:

public function captcha($token) {
    if (!$token) {
        $this->cakeError('error404');
    }
    $this->set(compact('token'));
}

<?php echo $this->Form->create('Verification', array('url' => array('controller' => 'users', 'action' => 'captcha', $token))); ?>
<?php echo $this->Recaptcha->display(); ?>
<?php echo $this->Form->hidden('token', array('value' => $token)); ?>
<?php echo $this->Form->end(__('I am human', true)); ?>

About

A component for CakePHP to throttle user activity.


Languages

Language:PHP 100.0%