I found temporary solution but I think is not right method:
/app/code/Marterosso/Autologin/Controller/Index/Index.php
<?php
namespace Marterosso\Autologin\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
protected $objectManager;
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->objectManager = $context->getObjectManager();
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$_params = $this->getRequest()->getParams();
$q = ( isset($_params["q"]) && !empty($_params["q"]) ) ? $_params["q"] : false;
if ($q) {
$params = [];
parse_str(base64_decode($q), $params);
$email = ( isset($params["username"]) && !empty($params["username"]) ) ? $params["username"] : false;
$password = ( isset($params["password"]) && !empty($params["password"]) ) ? $params["password"] : false;
if ($email && $password) {
/* @var $customerAccountManagement \Magento\Customer\Api\AccountManagementInterface */
$customerAccountManagement = $this->objectManager->get('Magento\Customer\Api\AccountManagementInterface');
$customerSession = $this->objectManager->get('Magento\Customer\Model\Session');
try {
/* @var $customer \Magento\Customer\Api\Data\CustomerInterface */
$customer = $customerAccountManagement->authenticate($email, $password);
$websiteId = $customer->getWebsiteId();
/* @var $_customer \Magento\Customer\Model\Customer */
$_customer = $this->objectManager
->get('Magento\Customer\Model\Customer')
->setWebsiteId($websiteId);
$customerSession->setCustomerAsLoggedIn($_customer->loadByEmail($email));
$this->_redirect('checkout/cart/');
} catch(\Magento\Framework\Exception\InvalidEmailOrPasswordException $ex) {
}
}
}
return $this->resultPageFactory->create();
}
}
/app/code/Marterosso/Autologin/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="autologin" id="autologin">
<module name="Marterosso_Autologin"/>
</route>
</router>
</config>
/app/code/Marterosso/Autologin/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Marterosso_Autologin" setup_version="1.0.0">
</module>
</config>
/app/code/Marterosso/Autologin/view/frontend/layout/autologin_index_index.xml
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<container name="customer.login.container" label="Customer Login Container" htmlTag="div" htmlClass="login-container">
<block class="Magento\Customer\Block\Form\Login" name="customer_form_login" template="form/login.phtml">
<container name="form.additional.info" as="form_additional_info"/>
</block>
<block class="Magento\Customer\Block\Form\Login\Info" name="customer.new" template="newcustomer.phtml"/>
</container>
</referenceContainer>
</body>
</page>
/app/code/Marterosso/Autologin/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Marterosso_Autologin',
__DIR__
);
Any other suggestions ?