Feed.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Rss\Controller;
  7. /**
  8. * Class Feed
  9. */
  10. abstract class Feed extends \Magento\Framework\App\Action\Action
  11. {
  12. /**
  13. * @var \Magento\Customer\Model\Session
  14. */
  15. protected $customerSession;
  16. /**
  17. * @var \Magento\Customer\Api\AccountManagementInterface
  18. */
  19. protected $customerAccountManagement;
  20. /**
  21. * @var \Magento\Framework\HTTP\Authentication
  22. */
  23. protected $httpAuthentication;
  24. /**
  25. * @var \Psr\Log\LoggerInterface
  26. */
  27. protected $logger;
  28. /**
  29. * @var \Magento\Rss\Model\RssManager
  30. */
  31. protected $rssManager;
  32. /**
  33. * @var \Magento\Rss\Model\RssFactory
  34. */
  35. protected $rssFactory;
  36. /**
  37. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  38. */
  39. protected $scopeConfig;
  40. /**
  41. * @param \Magento\Framework\App\Action\Context $context
  42. * @param \Magento\Rss\Model\RssManager $rssManager
  43. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  44. * @param \Magento\Rss\Model\RssFactory $rssFactory
  45. * @param \Magento\Customer\Model\Session $customerSession
  46. * @param \Magento\Customer\Api\AccountManagementInterface $customerAccountManagement
  47. * @param \Magento\Framework\HTTP\Authentication $httpAuthentication
  48. * @param \Psr\Log\LoggerInterface $logger
  49. */
  50. public function __construct(
  51. \Magento\Framework\App\Action\Context $context,
  52. \Magento\Rss\Model\RssManager $rssManager,
  53. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  54. \Magento\Rss\Model\RssFactory $rssFactory,
  55. \Magento\Customer\Model\Session $customerSession,
  56. \Magento\Customer\Api\AccountManagementInterface $customerAccountManagement,
  57. \Magento\Framework\HTTP\Authentication $httpAuthentication,
  58. \Psr\Log\LoggerInterface $logger
  59. ) {
  60. $this->rssManager = $rssManager;
  61. $this->scopeConfig = $scopeConfig;
  62. $this->rssFactory = $rssFactory;
  63. $this->customerSession = $customerSession;
  64. $this->customerAccountManagement = $customerAccountManagement;
  65. $this->httpAuthentication = $httpAuthentication;
  66. $this->logger = $logger;
  67. parent::__construct($context);
  68. }
  69. /**
  70. * @return bool
  71. */
  72. protected function auth()
  73. {
  74. if (!$this->customerSession->isLoggedIn()) {
  75. list($login, $password) = $this->httpAuthentication->getCredentials();
  76. try {
  77. $customer = $this->customerAccountManagement->authenticate($login, $password);
  78. $this->customerSession->setCustomerDataAsLoggedIn($customer);
  79. $this->customerSession->regenerateId();
  80. } catch (\Exception $e) {
  81. $this->logger->critical($e);
  82. }
  83. }
  84. if (!$this->customerSession->isLoggedIn()) {
  85. $this->httpAuthentication->setAuthenticationFailed('RSS Feeds');
  86. return false;
  87. }
  88. return true;
  89. }
  90. }