The error message is not showing on Login Observer if the error occours.
observer file is :
<?php
namespace Orbitx\Emailblock\Plugin;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\UrlInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\UrlFactory;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
class RedirectCustomUrl
{
protected $resultFactory;
protected $url;
protected $_request;
protected $_response;
protected $urlModel;
protected $resultRedirectFactory;
protected $messageManager;
protected $scopeConfig;
protected $MessageManager;
public function __construct(
\Magento\Framework\App\Action\Context $context,
UrlInterface $url,
UrlFactory $urlFactory,
RedirectFactory $redirectFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
ManagerInterface $messageManager,
ResultFactory $resultFactory,
\Magento\Framework\Message\ManagerInterface $MessageManager,
\Magento\Framework\App\ResponseFactory $responseFactory
)
{
$this->_request = $context->getRequest();
$this->MessageManager = $MessageManager;
$this->_response = $context->getResponse();
$this->url = $url;
$this->resultFactory = $resultFactory;
$this->urlModel = $urlFactory->create();
$this->resultRedirectFactory = $redirectFactory;
$this->scopeConfig = $scopeConfig;
$this->messageManager = $messageManager;
$this->_responseFactory = $responseFactory;
}
public function aroundExecute(\Magento\Customer\Controller\Account\LoginPost $subject, \Closure $proceed) {
$email = $subject->getRequest()->getPost('login')['username'];
if ($email == 'abc@getnada.com') {
$this->messageManager->addErrorMessage(
'Registration is disabled for you email'
);
$defaultUrl = $this->urlModel->getUrl('*/*/login', ['_secure' => true]);
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setUrl($defaultUrl);
}
return $proceed();
}
}
the exception 'Registration is disabled for you email' is not showing on frontend and if i entered wrong email or password it is also not giving any exception like 'your account is disabled'.
Can anyone tell me how to show the error message.
Any help is appriciated.