定制 davematics/superban 二次开发

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

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

davematics/superban

最新稳定版本:v1.0.0

Composer 安装命令:

composer require davematics/superban

包简介

This package will add the ability to ban a client completely for a period of time

README 文档

README

The package features a middleware named "superban," allowing you to control user access within your application.
If a user makes excessive requests within a specific timeframe, the middleware will temporarily block the user and later unblock them.

Installation

You can install the package via Composer:

composer require davematics/superban

Manually add the service provider to the providers array in config/app.php:

'Superban' => Davematics\Superban\Facades\Superban::class,

After installation, publish the configuration file:

 php artisan vendor:publish --provider="Davematics\Superban\SuperbanServiceProvider"

This will publish a superban.php file in your config directory.
Here you can Configure different cache drivers. - Redis, Database, etc.

USAGE

Route::middleware(['superban:300,5,2880'])->group(function () {

 Route::post('/add-interest', [App\Http\Controllers\SomeController::class, 'index']);

});
Route::post('/add-interest', [App\Http\Controllers\SomeController::class, 'index'])->middleware(['superban:300,5,2880']);

The middleware utilizes Laravel's RateLimiter class to track the number of attempts a user makes to access a resource within a specific time frame.
If the user surpasses the limit, the middleware generates a key based on the user's email, ID, or IP address and stores it in the cache for the designated time period. If the key is found in the cache, the middleware raises a UserBannedException.

Example

The "superban" middleware accepts three parameters:

The first parameter is the number of attempts a user can make before being banned.
The second parameter is number of minutes during which the user can attempt the route before facing a ban.
The last parameter is the number of minutes the user is banned.

On the route you can chnage the parameters 300, 5, 2880 based to fit in your specification.

Tests

To run the package tests, use the following bash command:

./vendor/bin/phpunit

Security

If you find any security-related concerns, kindly reach out via email to: davgwuche@gmail.com.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-12-21