This bundle is a simple solution to restrict user access to some controller for a specified timeline.
This could be used for different cases when you need to pre
- prevent flood - pushing users of irrelevant data;
- prevent user to visit page very often, etc.
- Require bundle with:
composer require
- Register bundle in AppKernel:
public function registerBundles()
{
$bundles = [
... ,
new NV\RequestLimitBundle\NVRequestLimitBundle()
];
...
}
- Configure bundle according to provider you use:
- Specify
restriction_time
in seconds:
nv_request_limit:
restriction_time: 5
In your controller action add following line to restrict user access by user id:
$this->get('nv.request_limit.request_restrictor')->restrictRequestByUserId($userId);
or following to restrict by user IP:
$this->get('nv.request_limit.request_restrictor')->restrictRequestByIp($userIp);
These will restrict user access to the action for 10 minutes.
- Write tests