| 
7 | 7 | 
 
  | 
8 | 8 | namespace Opengento\Gdpr\Controller;  | 
9 | 9 | 
 
  | 
10 |  | -use Magento\Customer\Controller\AccountInterface;  | 
 | 10 | +use Magento\Customer\Model\Session;  | 
 | 11 | +use Magento\Framework\App\RequestInterface;  | 
 | 12 | +use Magento\Framework\App\Response\Http;  | 
 | 13 | +use Magento\Framework\Controller\ResultFactory;  | 
 | 14 | +use Magento\Framework\Exception\NotFoundException;  | 
 | 15 | +use Magento\Framework\Message\ManagerInterface;  | 
 | 16 | +use Opengento\Gdpr\Model\Config;  | 
11 | 17 | 
 
  | 
12 |  | -abstract class AbstractPrivacy extends AbstractAction implements AccountInterface  | 
 | 18 | +/**  | 
 | 19 | + * This class is introduced to handle customer authentication verification.  | 
 | 20 | + * We can't use the default AccountInterface or AccountPlugin  | 
 | 21 | + * as they requires the action to inherit the default Magento AbstractAction  | 
 | 22 | + * which is deprecated and which suffer of performance issues  | 
 | 23 | + */  | 
 | 24 | +abstract class AbstractPrivacy extends AbstractAction  | 
13 | 25 | {  | 
 | 26 | +    /**  | 
 | 27 | +     * @var Session  | 
 | 28 | +     */  | 
 | 29 | +    protected $customerSession;  | 
 | 30 | + | 
 | 31 | +    /**  | 
 | 32 | +     * @var Http  | 
 | 33 | +     */  | 
 | 34 | +    private $response;  | 
 | 35 | + | 
 | 36 | +    public function __construct(  | 
 | 37 | +        RequestInterface $request,  | 
 | 38 | +        ResultFactory $resultFactory,  | 
 | 39 | +        ManagerInterface $messageManager,  | 
 | 40 | +        Config $config,  | 
 | 41 | +        Session $customerSession,  | 
 | 42 | +        Http $response  | 
 | 43 | +    ) {  | 
 | 44 | +        $this->customerSession = $customerSession;  | 
 | 45 | +        $this->response = $response;  | 
 | 46 | +        parent::__construct($request, $resultFactory, $messageManager, $config);  | 
 | 47 | +    }  | 
 | 48 | + | 
 | 49 | +    public function execute()  | 
 | 50 | +    {  | 
 | 51 | +        return $this->customerSession->authenticate() ? $this->defaultAction() : $this->response;  | 
 | 52 | +    }  | 
 | 53 | + | 
 | 54 | +    /**  | 
 | 55 | +     * @throws NotFoundException  | 
 | 56 | +     */  | 
 | 57 | +    private function defaultAction()  | 
 | 58 | +    {  | 
 | 59 | +        return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute();  | 
 | 60 | +    }  | 
14 | 61 | }  | 
0 commit comments