From e269272776e1c4960dd48f4ca64d67aa5980420a Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Wed, 24 Feb 2021 11:50:53 +0530 Subject: [PATCH] Allowed IP Exception Handled --- .../Middleware/CheckForMaintenanceMode.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/Webkul/Core/src/Http/Middleware/CheckForMaintenanceMode.php b/packages/Webkul/Core/src/Http/Middleware/CheckForMaintenanceMode.php index 1f84fd067..76b3bb9c7 100644 --- a/packages/Webkul/Core/src/Http/Middleware/CheckForMaintenanceMode.php +++ b/packages/Webkul/Core/src/Http/Middleware/CheckForMaintenanceMode.php @@ -23,7 +23,7 @@ class CheckForMaintenanceMode extends Original * @var \Webkul\Core\Models\Channel */ protected $channel; - + /** * Exclude route names. */ @@ -35,7 +35,7 @@ class CheckForMaintenanceMode extends Original protected $except = []; /** - * Exclude ips. + * Exclude IPs. */ protected $excludedIPs = []; @@ -49,14 +49,11 @@ class CheckForMaintenanceMode extends Original /* application */ $this->app = $app; - /* current channel */ - $this->channel = core()->getCurrentChannel(); - /* adding exception for admin routes */ $this->except[] = env('APP_ADMIN_URL', 'admin') . '*'; - /* adding exception for ips */ - $this->excludedIPs = array_map('trim', explode(',', $this->channel->allowed_ips)); + /* exclude ips */ + $this->setAllowedIps(); } /** @@ -106,7 +103,7 @@ class CheckForMaintenanceMode extends Original } } - if ($this->shouldPassThrough($request)) + if ($this->shouldPassThrough($request)) { return $response; } @@ -116,4 +113,18 @@ class CheckForMaintenanceMode extends Original return $next($request); } + + /** + * Set allowed IPs. + * + * @return void + */ + protected function setAllowedIps() + { + $this->channel = core()->getCurrentChannel(); + + if ($this->channel) { + $this->excludedIPs = array_map('trim', explode(',', $this->channel->allowed_ips)); + } + } } \ No newline at end of file