update: register ip limit

This commit is contained in:
tokumeikoi 2022-03-29 20:57:19 +08:00
parent d4183d2c7f
commit 7c473d6325

View File

@ -20,9 +20,11 @@ class AuthController extends Controller
{ {
public function register(AuthRegister $request) public function register(AuthRegister $request)
{ {
$registerCountByIP = CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()) || 0; if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
if ($registerCountByIP >= 3) { $registerCountByIP = Cache::get(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip())) ?? 0;
abort(500, __('Register frequently, please try again after 1 hour')); if ((int)$registerCountByIP >= 3) {
abort(500, __('Register frequently, please try again after 1 hour'));
}
} }
if ((int)config('v2board.recaptcha_enable', 0)) { if ((int)config('v2board.recaptcha_enable', 0)) {
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key')); $recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
@ -115,7 +117,10 @@ class AuthController extends Controller
$request->session()->put('id', $user->id); $request->session()->put('id', $user->id);
$user->last_login_at = time(); $user->last_login_at = time();
$user->save(); $user->save();
Cache::put(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()), $registerCountByIP + 1, 3600);
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
Cache::put(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()), (int)$registerCountByIP + 1, 3600);
}
return response()->json([ return response()->json([
'data' => $data 'data' => $data
]); ]);