Last active
December 4, 2017 15:26
-
-
Save magevision/dc407535997e761d56896746af15a81d to your computer and use it in GitHub Desktop.
Blog Post 24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MageVision\Blog24\Controller\Post; | |
use Magento\Framework\App\RequestInterface; | |
use Magento\Framework\App\Action\Action; | |
use Magento\Framework\App\Action\Context; | |
use Magento\Framework\View\Result\PageFactory; | |
use Magento\Customer\Model\Session; | |
class Index extends Action | |
{ | |
/** | |
* @var PageFactory | |
*/ | |
protected $resultPageFactory; | |
/** | |
* @var Session | |
*/ | |
protected $customerSession; | |
/** | |
* @param Context $context | |
* @param PageFactory $resultPageFactory | |
* @param Session $customerSession | |
*/ | |
public function __construct( | |
Context $context, | |
PageFactory $resultPageFactory, | |
Session $customerSession | |
) { | |
$this->resultPageFactory = $resultPageFactory; | |
$this->customerSession = $customerSession; | |
parent::__construct($context); | |
} | |
/** | |
* Allow only customers - redirect to login page | |
* | |
* @param RequestInterface $request | |
* @return \Magento\Framework\App\ResponseInterface | |
* @throws \Magento\Framework\Exception\NotFoundException | |
*/ | |
public function dispatch(RequestInterface $request) | |
{ | |
if (!$this->customerSession->authenticate()) { | |
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); | |
$this->customerSession->setBeforeAuthUrl($this->_url->getUrl( | |
'blog24/post/index' | |
)); | |
} | |
return parent::dispatch($request); | |
} | |
/** | |
* Default page | |
* | |
* @return \Magento\Framework\Controller\ResultInterface | |
*/ | |
public function execute() | |
{ | |
return $this->resultPageFactory->create(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="blog24" frontName="blog24"> | |
<module name="MageVision_Blog24" /> | |
</route> | |
</router> | |
</config> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment