I have created the custom module for custom login, but when I open the below link, it's not redirecting properly.
http://localhost/magento/custommodule/
Below is my route file code and path:
app\code\Vendor\Custommodule\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 id="custommodule" frontName="custommodule">
<module name="Vendor_Custommodule" />
</route>
</router>
</config>
layout file path:
app\code\Vendor\Custommodule\view\frontend\layout\pressroom_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="2columns-left">
<body>
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument translate="true" name="title" xsi:type="string">pressroom</argument>
</action>
</referenceBlock>
<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/mycusromlogin.phtml">
<container name="form.additional.info" as="form_additional_info"/>
</block>
</container>
</referenceContainer>
</body>
</page>
app\code\Vendor\Custommodule\Controller\Index\Index.php
<?php
namespace Vendor\Custommodule\Controller\Index;
use Magento\Framework\App\Action\Context;
use Magento\Framework\UrlInterface;
use Magento\Framework\App\Action\Action;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_resultPageFactory;
protected $urlInterface;
public function __construct(Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
UrlInterface $urlInterface,
\Magento\Customer\Model\Session $session)
{
$this->_resultPageFactory = $resultPageFactory;
$this->urlInterface = $urlInterface;
$this->_session = $session;
parent::__construct($context);
}
public function execute()
{
$url = $this->urlInterface->getUrl('custommodule/index/index');
// Create login URL
$login_url = $this->urlInterface->getUrl('custommodule/index/index', array('referer' => base64_encode($url))
);
// Redirect to login URL
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
if(!$this->_session->isLoggedIn()) {
//echo $login_url.'<br /> here'; die;
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($login_url);
return $resultRedirect;
}else{
//echo $login_url; die;
$resultPage = $this->_resultPageFactory->create();
return $resultPage;
}
}
}
The page isn’t redirecting properly
error.referer key
with route URL, so that when user will login they will redirect on same page after the login.custommodule/index/index
tocustomer/account/login