Skip to content

Instantly share code, notes, and snippets.

@sergeycherepanov
Created May 12, 2019 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeycherepanov/5391eadc05f5c6723a73f682adb3bb2c to your computer and use it in GitHub Desktop.
Save sergeycherepanov/5391eadc05f5c6723a73f682adb3bb2c to your computer and use it in GitHub Desktop.
<?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