|
|
@@ -14,6 +14,7 @@ class IpFilter
|
|
|
{
|
|
|
/**
|
|
|
* @throws BadRequestHttpException
|
|
|
+ * @return bool
|
|
|
*/
|
|
|
public function frontApiCheck($isLogin = false)
|
|
|
{
|
|
|
@@ -22,20 +23,21 @@ class IpFilter
|
|
|
$postParams = Yii::$app->request->post();
|
|
|
$remoteAddr = $_SERVER['REMOTE_ADDR']; // 获取用户 IP 地址
|
|
|
|
|
|
- // 登录接口不需要验证
|
|
|
+ //如果IP不在指定范围内
|
|
|
if (!self::remoteAddrCall($remoteAddr)) {
|
|
|
$logPreix = $isLogin ? 'nc_ip_filter_login' : 'nc_ip_filter_other';
|
|
|
$getLog = $logPreix . (is_array($getParams) ? json_encode($getParams) : $getParams);
|
|
|
$postLog = $logPreix . (is_array($postParams) ? json_encode($postParams) : $postParams);
|
|
|
LoggerTool::error($getLog);
|
|
|
LoggerTool::error($postLog);
|
|
|
- throw new \Exception('用户名或者密码错误');
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 判断IP是否在指定范围内
|
|
|
* @throws AddressNotFoundException
|
|
|
* @throws InvalidDatabaseException
|
|
|
*/
|