-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare (strict_types=1); | ||
|
||
namespace app\middleware; | ||
|
||
|
||
use plugin\CheckCaptcha; | ||
use think\facade\Validate; | ||
|
||
class RateLimit | ||
{ | ||
public function handle($request, \Closure $next) | ||
{ | ||
|
||
$class = '\\plugin\\' . plugin_class_get(plugin_alias_get()) . '\\App'; | ||
|
||
if (new $class() instanceof CheckCaptcha && $class::CHECK_CAPTCHA) { | ||
try { | ||
Validate::failException(true)->check([ | ||
'captcha' => request()->param('captcha') | ||
], [ | ||
'captcha|验证码' => 'require|captcha' | ||
]); | ||
} catch (\Exception $e) { | ||
return error($e->getMessage()); | ||
} | ||
} | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
// +---------------------------------------------------------------------- | ||
// | Captcha配置文件 | ||
// +---------------------------------------------------------------------- | ||
|
||
return [ | ||
//验证码位数 | ||
'length' => 5, | ||
// 验证码字符集合 | ||
'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY', | ||
// 验证码过期时间 | ||
'expire' => 1800, | ||
// 是否使用中文验证码 | ||
'useZh' => false, | ||
// 是否使用算术验证码 | ||
'math' => true, | ||
// 是否使用背景图 | ||
'useImgBg' => false, | ||
//验证码字符大小 | ||
'fontSize' => 25, | ||
// 是否使用混淆曲线 | ||
'useCurve' => true, | ||
//是否添加杂点 | ||
'useNoise' => true, | ||
// 验证码字体 不设置则随机 | ||
'fontttf' => '', | ||
//背景颜色 | ||
'bg' => [243, 251, 254], | ||
// 验证码图片高度 | ||
'imageH' => 0, | ||
// 验证码图片宽度 | ||
'imageW' => 0, | ||
|
||
// 添加额外的验证码设置 | ||
// verify => [ | ||
// 'length'=>4, | ||
// ... | ||
//], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
|
||
namespace plugin; | ||
|
||
interface CheckCaptcha | ||
{ | ||
const CHECK_CAPTCHA = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters