/** * @param \Magento\Backend\App\AbstractAction $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Backend\App\AbstractAction $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { $requestedActionName = $request->getActionName(); if (in_array($requestedActionName, $this->_openActions)) { $request->setDispatched(true); } else { if ($this->_auth->getUser()) { $this->_auth->getUser()->reload(); } if (!$this->_auth->isLoggedIn()) { $this->_processNotLoggedInUser($request); } else { $this->_auth->getAuthStorage()->prolong(); $backendApp = null; if ($request->getParam('app')) { $backendApp = $this->backendAppList->getCurrentApp(); } if ($backendApp) { $resultRedirect = $this->resultRedirectFactory->create(); $baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($this->backendUrl->getBaseUrl()); $baseUrl = $baseUrl . $backendApp->getStartupPage(); return $resultRedirect->setUrl($baseUrl); } } } $this->_auth->getAuthStorage()->refreshAcl(); return $proceed($request); }
/** * Validate and Match News Author and modify request * @param \Magento\Framework\App\RequestInterface $request * @return bool * //TODO: maybe remove this and use the url rewrite table. */ public function match(\Magento\Framework\App\RequestInterface $request) { if (!$this->dispatched) { $ipModel = $this->_ipFactory->create(); $ipCollection = $ipModel->getCollection(); $ip = $_SERVER['REMOTE_ADDR']; // echo $ip;die; $whitelists = $ipCollection->addFieldToFilter('member_access', 1)->addFieldToFilter('ip_address', $ip); //Get Ip exist in whitelist $arrayfilter = array_filter($whitelists->getData()); // Remove all empty values if (empty($arrayfilter)) { // check whether an array is empty or not //echo "hello";die; //foreach($whitelists as $ip){ //$whiteips[]=$ip->getIpAddress(); //} //if (!in_array($ip, $whiteips)){ $identifier = trim($request->getPathInfo(), '/'); //echo $identifier;die; // echo "wecome";die; //echo $ip;die; //if($ip=='172.17.0.1'){ //$request->setModuleName('firewall')->setControllerName('ipblock')->setActionName('ipblock'); $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 1); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); //} } return null; } return null; }
/** * @param string $action * @return $this */ public function forward($action) { $this->request->initForward(); if (!empty($this->params)) { $this->request->setParams($this->params); } if (!empty($this->controller)) { $this->request->setControllerName($this->controller); // Module should only be reset if controller has been specified if (!empty($this->module)) { $this->request->setModuleName($this->module); } } $this->request->setActionName($action); $this->request->setDispatched(false); return $this; }
/** * @param RequestInterface $request * @param ResponseInterface $response * @return bool */ public function load(RequestInterface $request, ResponseInterface $response) { $newsId = (int) $request->getParam('id'); if (!$newsId) { $request->initForward(); $request->setActionName('noroute'); $request->setDispatched(false); return false; } $news = $this->newsFactory->create()->load($newsId); $this->registry->register('current_news', $news); return true; }
/** * Validate and Match Cms Page and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return mixed */ public function match(\Magento\Framework\App\RequestInterface $request) { $identifier = trim($request->getPathInfo(), '/'); $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId()); if ($urlRewrite === null) { return null; } $redirectType = $urlRewrite->getRedirectType(); if ($redirectType) { $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302; $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode); $request->setDispatched(true); return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request)); } $request->setPathInfo('/' . $urlRewrite->getTargetPath()); return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request)); }
/** * @param RequestInterface $request * @param ResponseInterface $response * @return bool */ public function load(RequestInterface $request, ResponseInterface $response) { $orderId = (int) $request->getParam('order_id'); if (!$orderId) { $request->initForward(); $request->setActionName('noroute'); $request->setDispatched(false); return false; } $order = $this->orderFactory->create()->load($orderId); if ($this->orderAuthorization->canView($order)) { $this->registry->register('current_order', $order); return true; } $response->setRedirect($this->url->getUrl('*/*/history')); return false; }
/** * @param \Magento\Backend\App\AbstractAction $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Backend\App\AbstractAction $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { $requestedActionName = $request->getActionName(); if (in_array($requestedActionName, $this->_openActions)) { $request->setDispatched(true); } else { if ($this->_auth->getUser()) { $this->_auth->getUser()->reload(); } if (!$this->_auth->isLoggedIn()) { $this->_processNotLoggedInUser($request); } else { $this->_auth->getAuthStorage()->prolong(); } } $this->_auth->getAuthStorage()->refreshAcl(); return $proceed($request); }
/** * Validate and Match News Author and modify request * @param \Magento\Framework\App\RequestInterface $request * @return bool * //TODO: maybe remove this and use the url rewrite table. */ public function match(\Magento\Framework\App\RequestInterface $request) { if (!$this->dispatched) { $ipModel = $this->_ipFactory->create(); $ipCollection = $ipModel->getCollection(); $ip = $_SERVER['REMOTE_ADDR']; $ip_access = $this->ipaccessObject->getIpaccess($ipModel); //echo $ip_access;die; //$ip_collections=$ipCollection->addFieldToFilter('ip_address',$ip)->getData(); //Get Ip collections if ($ip_access == 0) { // check whether an ip is in blacklist //0 -Black, 1-White $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 1); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } return null; } return null; }
/** * Validate and Match Cms Page and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ public function match(\Magento\Framework\App\RequestInterface $request) { $identifier = trim($request->getPathInfo(), '/'); $condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true)); $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition)); $identifier = $condition->getIdentifier(); if ($condition->getRedirectUrl()) { $this->_response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request)); } if (!$condition->getContinue()) { return null; } /** @var \Magento\Cms\Model\Page $page */ $page = $this->_pageFactory->create(); $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId()); if (!$pageId) { return null; } $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request)); }
/** * Validate and Match News Author and modify request * @param \Magento\Framework\App\RequestInterface $request * @return bool * //TODO: maybe remove this and use the url rewrite table. */ public function match(RequestInterface $request) { if (!$this->dispatched) { $urlKey = trim($request->getPathInfo(), '/'); $origUrlKey = $urlKey; /** @var Object $condition */ $condition = new Object(['url_key' => $urlKey, 'continue' => true]); $this->eventManager->dispatch('sample_news_controller_router_match_before', ['router' => $this, 'condition' => $condition]); $urlKey = $condition->getUrlKey(); if ($condition->getRedirectUrl()) { $this->response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); } if (!$condition->getContinue()) { return null; } $entities = ['author' => ['prefix' => $this->scopeConfig->getValue('sample_news/author/url_prefix', ScopeInterface::SCOPE_STORES), 'suffix' => $this->scopeConfig->getValue('sample_news/author/url_suffix', ScopeInterface::SCOPE_STORES), 'list_key' => $this->scopeConfig->getValue('sample_news/author/list_url', ScopeInterface::SCOPE_STORES), 'list_action' => 'index', 'factory' => $this->authorFactory, 'controller' => 'author', 'action' => 'view', 'param' => 'id']]; foreach ($entities as $entity => $settings) { if ($settings['list_key']) { if ($urlKey == $settings['list_key']) { $request->setModuleName('sample_news')->setControllerName($settings['controller'])->setActionName($settings['list_action']); $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } if ($settings['prefix']) { $parts = explode('/', $urlKey); if ($parts[0] != $settings['prefix'] || count($parts) != 2) { continue; } $urlKey = $parts[1]; } if ($settings['suffix']) { $suffix = substr($urlKey, -strlen($settings['suffix']) - 1); if ($suffix != '.' . $settings['suffix']) { continue; } $urlKey = substr($urlKey, 0, -strlen($settings['suffix']) - 1); } /** @var \Sample\News\Model\Author $instance */ $instance = $settings['factory']->create(); $id = $instance->checkUrlKey($urlKey, $this->storeManager->getStore()->getId()); if (!$id) { return null; } $request->setModuleName('sample_news')->setControllerName('author')->setActionName('view')->setParam('id', $id); $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } return null; }
/** * Validate and Match Blog Pages and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ public function match(\Magento\Framework\App\RequestInterface $request) { $_identifier = trim($request->getPathInfo(), '/'); $pathInfo = explode('/', $_identifier); $blogRoute = $this->_url->getRoute(); if ($pathInfo[0] != $blogRoute) { return; } unset($pathInfo[0]); switch ($this->_url->getPermalinkType()) { case Url::PERMALINK_TYPE_DEFAULT: foreach ($pathInfo as $i => $route) { $pathInfo[$i] = $this->_url->getControllerName($route); } break; case Url::PERMALINK_TYPE_SHORT: if ($pathInfo[1] == $this->_url->getRoute(Url::CONTROLLER_SEARCH)) { $pathInfo[1] = Url::CONTROLLER_SEARCH; } elseif (count($pathInfo) == 1) { if ($this->_isArchiveIdentifier($pathInfo[1])) { $pathInfo[2] = $pathInfo[1]; $pathInfo[1] = Url::CONTROLLER_ARCHIVE; } elseif ($postId = $this->_getPostId($pathInfo[1])) { $pathInfo[2] = $pathInfo[1]; $pathInfo[1] = Url::CONTROLLER_POST; } elseif ($categoryId = $this->_getCategoryId($pathInfo[1])) { $pathInfo[2] = $pathInfo[1]; $pathInfo[1] = Url::CONTROLLER_CATEGORY; } } break; } $identifier = implode('/', $pathInfo); $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]); $this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]); if ($condition->getRedirectUrl()) { $this->_response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); } if (!$condition->getContinue()) { return null; } $identifier = $condition->getIdentifier(); $success = false; $info = explode('/', $identifier); if (!$identifier) { $request->setModuleName('blog')->setControllerName('index')->setActionName('index'); $success = true; } elseif (count($info) > 1) { $store = $this->_storeManager->getStore()->getId(); switch ($info[0]) { case 'post': if (!($postId = $this->_getPostId($info[1]))) { return null; } $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId); $success = true; break; case 'category': if (!($categoryId = $this->_getCategoryId($info[1]))) { return null; } $request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId); $success = true; break; case 'archive': $request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]); $success = true; break; case 'search': $request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]); $success = true; break; case 'rss': $request->setModuleName('blog')->setControllerName('rss')->setActionName(isset($info[1]) ? $info[1] : 'index'); $success = true; break; } } if (!$success) { return null; } $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); }
/** * @param \Magento\Framework\App\RequestInterface $request * @param string $url * @param int $code * @return \Magento\Framework\App\ActionInterface */ protected function redirect($request, $url, $code) { $this->response->setRedirect($url, $code); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); }
/** * Validate and Match Blog Pages and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ public function match(\Magento\Framework\App\RequestInterface $request) { $_identifier = trim($request->getPathInfo(), '/'); if (strpos($_identifier, 'blog') !== 0) { return; } $identifier = str_replace(array('blog/', 'blog'), '', $_identifier); $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]); $this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]); if ($condition->getRedirectUrl()) { $this->_response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); } if (!$condition->getContinue()) { return null; } $identifier = $condition->getIdentifier(); $success = false; $info = explode('/', $identifier); if (!$identifier) { $request->setModuleName('blog')->setControllerName('index')->setActionName('index'); $success = true; } elseif (count($info) > 1) { $store = $this->_storeManager->getStore()->getId(); switch ($info[0]) { case 'post': $post = $this->_postFactory->create(); $postId = $post->checkIdentifier($info[1], $this->_storeManager->getStore()->getId()); if (!$postId) { return null; } $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId); $success = true; break; case 'category': $category = $this->_categoryFactory->create(); $categoryId = $category->checkIdentifier($info[1], $this->_storeManager->getStore()->getId()); if (!$categoryId) { return null; } $request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId); $success = true; break; case 'archive': $request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]); $success = true; break; case 'search': $request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]); $success = true; break; } } if (!$success) { return null; } $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); }
/** * @param RequestInterface $request * @return ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(RequestInterface $request) { $request->setDispatched(false); return $this->_response; }
/** * @param RequestInterface $request * @return \Magento\Framework\App\ActionInterface */ public function match(RequestInterface $request) { $_brandHelper = $this->_brandHelper; if (!$this->dispatched) { $urlKey = trim($request->getPathInfo(), '/'); $origUrlKey = $urlKey; /** @var Object $condition */ $condition = new DataObject(['url_key' => $urlKey, 'continue' => true]); $this->eventManager->dispatch('ves_brand_controller_router_match_before', ['router' => $this, 'condition' => $condition]); $urlKey = $condition->getUrlKey(); if ($condition->getRedirectUrl()) { $this->response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]); } if (!$condition->getContinue()) { return null; } $route = $_brandHelper->getConfig('general_settings/route'); if ($urlKey == $route) { $request->setModuleName('vesbrand')->setControllerName('index')->setActionName('index'); $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } $url_prefix = $_brandHelper->getConfig('general_settings/url_prefix'); $url_suffix = $_brandHelper->getConfig('general_settings/url_suffix'); $identifiers = explode('/', $urlKey); //Check Group Url if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = ''; if (trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = str_replace($url_suffix, '', $identifiers[0]); } if (count($identifiers) == 2) { $brandUrl = str_replace($url_suffix, '', $identifiers[1]); } $group = $this->_groupCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem(); if ($group && $group->getId()) { $request->setModuleName('vesbrand')->setControllerName('group')->setActionName('view')->setParam('group_id', $group->getId()); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } // Check Brand Url Key if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) { if (count($identifiers) == 2) { $brandUrl = str_replace($url_suffix, '', $identifiers[1]); } if (trim($url_prefix) == '' && count($identifiers) == 1) { $brandUrl = str_replace($url_suffix, '', $identifiers[0]); } $brand = $this->_brandCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem(); if ($brand && $brand->getId() && (in_array($this->storeManager->getStore()->getId(), $brand->getStoreId()) || in_array(0, $brand->getStoreId()))) { $request->setModuleName('vesbrand')->setControllerName('brand')->setActionName('view')->setParam('brand_id', $brand->getId()); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey); $request->setDispatched(true); $this->dispatched = true; return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]); } } } }