Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex 00 ip restrict block country #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Restricy Few Countries from accessing website
Restricy Few Countries from accessing website
  • Loading branch information
abhijitdpatel committed Aug 28, 2018
commit 86e232f070e0a41533a5901a9281b6b2c9a53be0
27 changes: 27 additions & 0 deletions app/code/MyCompany/IpRestrict/Observer/CountryObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace MyCompany\IpRestrict\Observer;


class CountryObserver implements \Magento\Framework\Event\ObserverInterface

{
public function __construct(
\MyCompany\IpRestrict\Model\Country $country
) {
$this->modelCountry = $country;
}
/**
* Below is the method that will fire whenever the event runs!
*
* @param Observer $observer
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$objCountry = $this->modelCountry->getCountryCode();
if($objCountry->geoplugin_countryCode=='CN' || $objCountry->geoplugin_countryCode=='RU')
{
echo "<h1>You are not allowed to access website</h1>";
exit();
}
}
}
6 changes: 6 additions & 0 deletions app/code/MyCompany/IpRestrict/etc/frontend/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch">
<observer name="MyCompany_IpRestrict_Restriction" instance="MyCompany\IpRestrict\Observer\CountryObserver" />
</event>
</config>