Authentication.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\Order\Plugin;
  8. use Magento\Framework\App\RequestInterface;
  9. class Authentication
  10. {
  11. /**
  12. * @var \Magento\Customer\Model\Url
  13. */
  14. protected $customerUrl;
  15. /**
  16. * @var \Magento\Customer\Model\Session
  17. */
  18. protected $customerSession;
  19. /**
  20. * @param \Magento\Customer\Model\Url $customerUrl
  21. * @param \Magento\Customer\Model\Session $customerSession
  22. */
  23. public function __construct(
  24. \Magento\Customer\Model\Url $customerUrl,
  25. \Magento\Customer\Model\Session $customerSession
  26. ) {
  27. $this->customerUrl = $customerUrl;
  28. $this->customerSession = $customerSession;
  29. }
  30. /**
  31. * Authenticate user
  32. *
  33. * @param \Magento\Framework\App\ActionInterface $subject
  34. * @param RequestInterface $request
  35. * @return void
  36. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  37. */
  38. public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
  39. {
  40. $loginUrl = $this->customerUrl->getLoginUrl();
  41. if (!$this->customerSession->authenticate($loginUrl)) {
  42. $subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true);
  43. }
  44. }
  45. }