本文整理汇总了PHP中Magento\Framework\Event\Observer::getControllerAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::getControllerAction方法的具体用法?PHP Observer::getControllerAction怎么用?PHP Observer::getControllerAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Event\Observer
的用法示例。
在下文中一共展示了Observer::getControllerAction方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Check Captcha On User Login Backend Page
*
* @param \Magento\Framework\Event\Observer $observer
* @throws \Magento\Framework\Exception\Plugin\AuthenticationException
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'backend_forgotpassword';
$captchaModel = $this->_helper->getCaptcha($formId);
$controller = $observer->getControllerAction();
$email = (string) $observer->getControllerAction()->getRequest()->getParam('email');
$params = $observer->getControllerAction()->getRequest()->getParams();
if (!empty($email) && !empty($params)) {
if ($captchaModel->isRequired()) {
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->_session->setEmail((string) $controller->getRequest()->getPost('email'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$controller->getResponse()->setRedirect($controller->getUrl('*/*/forgotpassword', ['_nosecret' => true]));
}
}
}
return $this;
}
示例2: execute
/**
* Redirects tracking popup to specific URL
* @param \Magento\Framework\Event\Observer $observer
*
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$shippingInfoModel = $this->_shippingInfoFactory->create()->loadByHash($this->_request->getParam('hash'));
if ($url = $this->shipmentHelper->getTrackingUrlByShippingInfo($shippingInfoModel)) {
$controller = $observer->getControllerAction();
$controller->getResponse()->setRedirect($url);
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
}
return $observer;
}
示例3: execute
/**
* bindCustomerLogin
*
* @param Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$action = $observer->getControllerAction();
$actionArray = array();
$actionArray['Controller Name'] = $action->getRequest()->getControllerName();
$actionArray['Action Name'] = $action->getRequest()->getActionName();
$actionArray['Module Name'] = $action->getRequest()->getRouteName();
$actionArray['Path Info'] = $action->getRequest()->getPathInfo();
$this->actions[] = $actionArray;
$this->_devtoolData->addDevToolData($this->_devtoolData->_requestKey, $this->actions);
}
示例4: execute
/**
* Check CAPTCHA on Contact Us page
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'contact_us';
$captcha = $this->_helper->getCaptcha($formId);
if ($captcha->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), 'contact/index/index');
}
}
}
示例5: execute
/**
* Check Captcha On Checkout as Guest Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'guest_checkout';
$captchaModel = $this->_helper->getCaptcha($formId);
$checkoutMethod = $this->_typeOnepage->getQuote()->getCheckoutMethod();
if ($checkoutMethod == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
if ($captchaModel->isRequired()) {
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$result = ['error' => 1, 'message' => __('Incorrect CAPTCHA')];
$controller->getResponse()->representJson($this->jsonHelper->jsonEncode($result));
}
}
}
return $this;
}
示例6: 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_create';
$captchaModel = $this->_helper->getCaptcha($formId);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_session->setCustomerFormData($controller->getRequest()->getPostValue());
$url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]);
$controller->getResponse()->setRedirect($this->redirect->error($url));
}
}
return $this;
}
示例7: 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;
}
示例8: 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;
}
示例9: execute
/**
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
try {
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
$this->accountManagementHelper->processCustomerLockoutData($customer->getId());
$this->customerRepository->save($customer);
} catch (NoSuchEntityException $e) {
//do nothing as customer existance is validated later in authenticate method
}
$this->workWithLock();
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}
$customer = $this->customerSession->getCustomer();
$login = $customer->getEmail();
$captchaModel->logAttempt($login);
return $this;
}
示例10: execute
/**
* Process redirect to the product page if this is the only search result.
*
* @param Observer $observer The observer
* @event controller_action_postdispatch_catalogsearch_result_index
*
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->scopeConfig->isSetFlag(self::REDIRECT_SETTINGS_CONFIG_XML_FLAG)) {
$layer = $this->layerResolver->get();
$layerState = $layer->getState();
if (count($layerState->getFilters()) === 0) {
$productCollection = $layer->getProductCollection();
if ($productCollection->getCurPage() === 1 && $productCollection->getSize() === 1) {
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
$product = $productCollection->getFirstItem();
if ($product->getId()) {
$this->addRedirectMessage($product);
$observer->getControllerAction()->getResponse()->setRedirect($product->getProductUrl());
}
}
}
}
}
示例11: execute
/**
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
$customerId = $this->customerSession->getCustomerId();
$this->authentication->processAuthenticationFailure($customerId);
if ($this->authentication->isLocked($customerId)) {
$this->customerSession->logout();
$this->customerSession->start();
$message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
$this->messageManager->addError($message);
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}
$customer = $this->customerSession->getCustomer();
$login = $customer->getEmail();
$captchaModel->logAttempt($login);
return $this;
}