-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Badgeuse : être plus libre dans le choix des IP + refactoring (#1082)
* Move isLocationOk to new helper * Use startswith instead of equals * fix import
- Loading branch information
Showing
4 changed files
with
48 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace AppBundle\Helper; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerInterface as Container; | ||
|
||
class PlaceIP { | ||
|
||
private $container; | ||
|
||
public function __construct(Container $container) { | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* If enable_place_local_ip_address_check is true & place_local_ip_address is set | ||
* Then we check the client's IP against the IP list | ||
*/ | ||
public function isLocationOk() | ||
{ | ||
$checkIps = $this->container->getParameter('enable_place_local_ip_address_check'); | ||
|
||
if (isset($checkIps) and $checkIps) { | ||
$whitelist_ips = $this->container->getParameter('place_local_ip_address'); | ||
$whitelist_ips = explode(',', $whitelist_ips); | ||
$current_ip = $this->container->get('request_stack')->getCurrentRequest()->getClientIp(); | ||
|
||
$current_ip_in_whitelist_ips = array_filter($whitelist_ips, function($whitelist_ip) use ($current_ip) { | ||
return str_starts_with($current_ip, $whitelist_ip); | ||
}); | ||
if (count($current_ip_in_whitelist_ips)) { | ||
return True; | ||
} | ||
} | ||
|
||
return False; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters