Configure.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * MageSpecialist
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@magespecialist.it so we can send you a copy immediately.
  14. *
  15. * @category MSP
  16. * @package MSP_TwoFactorAuth
  17. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. */
  20. namespace MSP\TwoFactorAuth\Controller\Adminhtml\Google;
  21. use Magento\Backend\Model\Auth\Session;
  22. use Magento\Backend\App\Action;
  23. use Magento\Framework\View\Result\PageFactory;
  24. use MSP\TwoFactorAuth\Api\TfaInterface;
  25. use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
  26. use MSP\TwoFactorAuth\Model\Provider\Engine\Google;
  27. /**
  28. * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  29. */
  30. class Configure extends AbstractAction
  31. {
  32. /**
  33. * @var TfaInterface
  34. */
  35. private $tfa;
  36. /**
  37. * @var Session
  38. */
  39. private $session;
  40. /**
  41. * @var PageFactory
  42. */
  43. private $pageFactory;
  44. public function __construct(
  45. Action\Context $context,
  46. Session $session,
  47. PageFactory $pageFactory,
  48. TfaInterface $tfa
  49. ) {
  50. parent::__construct($context);
  51. $this->tfa = $tfa;
  52. $this->session = $session;
  53. $this->pageFactory = $pageFactory;
  54. }
  55. /**
  56. * Get current user
  57. * @return \Magento\User\Model\User|null
  58. */
  59. private function getUser()
  60. {
  61. return $this->session->getUser();
  62. }
  63. public function execute()
  64. {
  65. return $this->pageFactory->create();
  66. }
  67. /**
  68. * Check if admin has permissions to visit related pages
  69. *
  70. * @return bool
  71. */
  72. protected function _isAllowed()
  73. {
  74. $user = $this->getUser();
  75. return
  76. $user &&
  77. $this->tfa->getProviderIsAllowed($user->getId(), Google::CODE) &&
  78. !$this->tfa->getProvider(Google::CODE)->isActive($user->getId());
  79. }
  80. }