fidelo-software / laravel-spamshield
简单的垃圾邮件检测
v2.1.2
2023-03-22 10:01 UTC
Requires
- php: ^8.0
- illuminate/http: 9.*
- illuminate/support: 9.*
Requires (Dev)
- pestphp/pest: ^1.22
- pestphp/pest-plugin-mock: ^1.0
README
安装
通过composer安装此包
composer require fidelo-software/laravel-spamshield
基本用法
使用您想要使用的策略生成spamshield实例
$spamshield = new \FideloSoftware\Spam\SpamShield( [ new \FideloSoftware\Spam\Strategies\HoneypotStrategy(3), new \FideloSoftware\Spam\Strategies\TimestampStrategy($store, 5), new \FideloSoftware\Spam\Strategies\LinkStrategy(0), new \FideloSoftware\Spam\Strategies\ValueBlacklistStrategy(['name' => ['John Doe']]), ], $store $logger // optional );
在表单初始化时启动所有策略的onload进程
// Form initialization $spamshield->onload($form, $request);
在您的表单渲染过程中包含定义策略的所有HTML部分
// Form rendering echo $spamshield->html($form);
在表单提交时执行所有策略以检查垃圾邮件
// Submit try { $spamshield->detect($form, $request); } catch(\FideloSoftware\Spam\Exceptions\BannedException $e) { ... } catch(\FideloSoftware\Spam\Exceptions\SpamDetectionException $e) { ... }
全局检查用户请求
// Check if user is globally banned after to many attempts \FideloSoftware\Spam\SpamShield::isBanned($store, $request);