update: add register ip limit

This commit is contained in:
tokumeikoi
2022-03-29 21:11:37 +08:00
parent 7c473d6325
commit e3ffdb7bce
5 changed files with 15 additions and 5 deletions

View File

@ -22,7 +22,7 @@ class AuthController extends Controller
{
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
$registerCountByIP = Cache::get(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip())) ?? 0;
if ((int)$registerCountByIP >= 3) {
if ((int)$registerCountByIP >= (int)config('v2board.register_limit_count', 3)) {
abort(500, __('Register frequently, please try again after 1 hour'));
}
}
@ -119,7 +119,11 @@ class AuthController extends Controller
$user->save();
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
Cache::put(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()), (int)$registerCountByIP + 1, 3600);
Cache::put(
CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()),
(int)$registerCountByIP + 1,
(int)config('v2board.register_limit_expire', 60) * 60
);
}
return response()->json([
'data' => $data