本文整理汇总了PHP中Magento\Framework\Session\SessionManagerInterface::getBeforeAuthUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionManagerInterface::getBeforeAuthUrl方法的具体用法?PHP SessionManagerInterface::getBeforeAuthUrl怎么用?PHP SessionManagerInterface::getBeforeAuthUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Session\SessionManagerInterface
的用法示例。
在下文中一共展示了SessionManagerInterface::getBeforeAuthUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Check captcha on user login page
*
* @param \Magento\Framework\Event\Observer $observer
* @throws NoSuchEntityException
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'user_login';
$captchaModel = $this->_helper->getCaptcha($formId);
$controller = $observer->getControllerAction();
$loginParams = $controller->getRequest()->getPost('login');
$login = is_array($loginParams) && array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
if ($captchaModel->isRequired($login)) {
$word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId);
if (!$captchaModel->isCorrect($word)) {
try {
$customer = $this->getCustomerRepository()->get($login);
$this->getAuthentication()->processAuthenticationFailure($customer->getId());
} catch (NoSuchEntityException $e) {
//do nothing as customer existance is validated later in authenticate method
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setUsername($login);
$beforeUrl = $this->_session->getBeforeAuthUrl();
$url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl();
$controller->getResponse()->setRedirect($url);
}
}
$captchaModel->logAttempt($login);
return $this;
}
示例2: execute
/**
* Check Captcha On User Login Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'user_login';
$captchaModel = $this->_helper->getCaptcha($formId);
$controller = $observer->getControllerAction();
$loginParams = $controller->getRequest()->getPost('login');
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
if ($captchaModel->isRequired($login)) {
$word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId);
if (!$captchaModel->isCorrect($word)) {
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setUsername($login);
$beforeUrl = $this->_session->getBeforeAuthUrl();
$url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl();
$controller->getResponse()->setRedirect($url);
}
}
$captchaModel->logAttempt($login);
return $this;
}