Configure.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  16. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. */
  18. namespace MSP\TwoFactorAuth\Controller\Adminhtml\U2f;
  19. use Magento\Backend\App\Action;
  20. use Magento\Backend\Model\Auth\Session;
  21. use Magento\Framework\App\ResponseInterface;
  22. use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
  23. use MSP\TwoFactorAuth\Model\Provider\Engine\U2fKey;
  24. use MSP\TwoFactorAuth\Model\Tfa;
  25. /**
  26. * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  27. */
  28. class Configure extends AbstractAction
  29. {
  30. /**
  31. * @var Tfa
  32. */
  33. private $tfa;
  34. /**
  35. * @var Session
  36. */
  37. private $session;
  38. public function __construct(
  39. Tfa $tfa,
  40. Session $session,
  41. Action\Context $context
  42. ) {
  43. $this->tfa = $tfa;
  44. $this->session = $session;
  45. parent::__construct($context);
  46. }
  47. /**
  48. * Dispatch request
  49. *
  50. * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
  51. */
  52. public function execute()
  53. {
  54. $this->_view->loadLayout();
  55. $this->_view->renderLayout();
  56. return $this->getResponse();
  57. }
  58. /**
  59. * @return \Magento\User\Model\User|null
  60. */
  61. private function getUser()
  62. {
  63. return $this->session->getUser();
  64. }
  65. /**
  66. * Check if admin has permissions to visit related pages
  67. *
  68. * @return bool
  69. */
  70. protected function _isAllowed()
  71. {
  72. $user = $this->getUser();
  73. return
  74. $user &&
  75. $this->tfa->getProviderIsAllowed($user->getId(), U2fKey::CODE) &&
  76. !$this->tfa->getProvider(U2fKey::CODE)->isActive($user->getId());
  77. }
  78. }