Просмотр исходного кода

Merge branch 'feature/ip_check_new_limit' into feature/NC-45

jerry 1 год назад
Родитель
Сommit
2f0535e3b9

+ 1 - 1
backendApi/modules/v1/controllers/BaseController.php

@@ -49,7 +49,7 @@ class BaseController extends \yii\rest\ActiveController {
         ];
 
         $request = Yii::$app->request;
-        if (\Yii::$app->redis->get('backend_ip_filter') && !in_array($request->getUrl(), $notFilterApi)) {
+        if (\Yii::$app->redis->get('backend_ip_filter') && !Tool::checkArrayElementSubstringOfString($request->getUrl(), $notFilterApi)) {
             if (!(new IpFilter())->checkIp('backend')) {
                 throw new \Exception('用户名或密码错误');
             }

+ 15 - 0
common/helpers/Tool.php

@@ -588,4 +588,19 @@ class Tool {
 
         return true;
     }
+
+    function checkArrayElementSubstringOfString(string $string, array $array) {
+        if (empty($string) || empty($array)) {
+            return false;
+        }
+
+        foreach ($array as $substr) {
+            if (strpos($string, $substr) !== false) {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+
 }

+ 2 - 1
frontendApi/modules/v1/controllers/BaseController.php

@@ -11,6 +11,7 @@ namespace frontendApi\modules\v1\controllers;
 use common\components\ActiveRecord;
 use common\helpers\Date;
 use common\helpers\Form;
+use common\helpers\Tool;
 use common\libs\IpFilter;
 use frontendApi\modules\v1\models\User;
 use Yii;
@@ -63,7 +64,7 @@ class BaseController extends \yii\rest\ActiveController {
         ];
 
         $request = Yii::$app->request;
-        if (\Yii::$app->redis->get('member_ip_filter') && !in_array($request->getUrl(), $notFilterApi)) {
+        if (\Yii::$app->redis->get('member_ip_filter') && !Tool::checkArrayElementSubstringOfString($request->getUrl(), $notFilterApi)) {
             if (!(new IpFilter())->checkIp('member')) {
                 throw new \Exception('用户名或密码错误');
             }