Created
May 12, 2019 11:10
-
-
Save sergeycherepanov/5391eadc05f5c6723a73f682adb3bb2c to your computer and use it in GitHub Desktop.
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
<?php | |
namespace mage2login; | |
use Magento\Customer\Model\ResourceModel\CustomerRepository; | |
use Magento\Customer\Model\Session; | |
use Magento\Framework\App\ObjectManager; | |
use Magento\Framework\App\State; | |
if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) { | |
echo "Usage: {$_SERVER['REQUEST_URI']}?id=%CUSTOMER_ID%"; | |
die(); | |
} | |
if (is_file(__DIR__ . '/app/bootstrap.php')) { | |
require __DIR__ . '/app/bootstrap.php'; | |
} elseif (is_file(__DIR__ . '/../app/bootstrap.php')) { | |
require __DIR__ . '/../app/bootstrap.php'; | |
} else { | |
die('Can't find bootstrap.php'); | |
} | |
\Magento\Framework\App\Bootstrap::create(BP, $_SERVER); | |
$om = ObjectManager::getInstance(); | |
$om->get(State::class)->setAreaCode('frontend'); | |
$session = $om->get(Session::class); | |
$customer = $om->get(CustomerRepository::class)->getById($_REQUEST['id']); | |
if ($session->loginById($customer->getId())) { | |
echo "You was logged in"; | |
} else { | |
echo "You wasn't logged in"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment