Customer.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Controller;
  7. use Magento\Framework\App\Action\Action;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Customer\Model\Session;
  10. use Magento\Framework\App\RequestInterface;
  11. /**
  12. * Customer reviews controller
  13. */
  14. abstract class Customer extends Action
  15. {
  16. /**
  17. * Customer session model
  18. *
  19. * @var \Magento\Customer\Model\Session
  20. */
  21. protected $customerSession;
  22. /**
  23. * @param \Magento\Framework\App\Action\Context $context
  24. * @param \Magento\Customer\Model\Session $customerSession
  25. */
  26. public function __construct(
  27. Context $context,
  28. Session $customerSession
  29. ) {
  30. $this->customerSession = $customerSession;
  31. parent::__construct($context);
  32. }
  33. /**
  34. * Check customer authentication for some actions
  35. *
  36. * @param \Magento\Framework\App\RequestInterface $request
  37. * @return \Magento\Framework\App\ResponseInterface
  38. */
  39. public function dispatch(RequestInterface $request)
  40. {
  41. if (!$this->customerSession->authenticate()) {
  42. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  43. }
  44. return parent::dispatch($request);
  45. }
  46. }