Configure.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\Authy;
  21. use Magento\Backend\App\Action;
  22. use Magento\Backend\Model\Auth\Session;
  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\Authy;
  27. /**
  28. * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  29. */
  30. class Configure extends AbstractAction
  31. {
  32. /**
  33. * @var PageFactory
  34. */
  35. private $pageFactory;
  36. /**
  37. * @var Session
  38. */
  39. private $session;
  40. /**
  41. * @var TfaInterface
  42. */
  43. private $tfa;
  44. /**
  45. * Configure constructor.
  46. * @param Action\Context $context
  47. * @param Session $session
  48. * @param TfaInterface $tfa
  49. * @param PageFactory $pageFactory
  50. */
  51. public function __construct(
  52. Action\Context $context,
  53. Session $session,
  54. TfaInterface $tfa,
  55. PageFactory $pageFactory
  56. ) {
  57. parent::__construct($context);
  58. $this->pageFactory = $pageFactory;
  59. $this->session = $session;
  60. $this->tfa = $tfa;
  61. }
  62. /**
  63. * Get current user
  64. * @return \Magento\User\Model\User|null
  65. */
  66. private function getUser()
  67. {
  68. return $this->session->getUser();
  69. }
  70. /**
  71. * @inheritdoc
  72. */
  73. public function execute()
  74. {
  75. return $this->pageFactory->create();
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. protected function _isAllowed()
  81. {
  82. $user = $this->getUser();
  83. return
  84. $user &&
  85. $this->tfa->getProviderIsAllowed($user->getId(), Authy::CODE) &&
  86. !$this->tfa->getProvider(Authy::CODE)->isActive($user->getId());
  87. }
  88. }