Browse Source

update: register ip limit

tokumeikoi 3 years ago
parent
commit
7c473d6325
1 changed files with 9 additions and 4 deletions
  1. 9 4
      app/Http/Controllers/Passport/AuthController.php

+ 9 - 4
app/Http/Controllers/Passport/AuthController.php

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