Revoke.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Tfa;
  21. use Magento\Backend\App\Action;
  22. use Magento\Framework\App\ResponseInterface;
  23. use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
  24. use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
  25. /**
  26. * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  27. */
  28. class Revoke extends AbstractAction
  29. {
  30. /**
  31. * @var TrustedManagerInterface
  32. */
  33. private $trustedManager;
  34. public function __construct(
  35. Action\Context $context,
  36. TrustedManagerInterface $trustedManager
  37. ) {
  38. parent::__construct($context);
  39. $this->trustedManager = $trustedManager;
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function execute()
  45. {
  46. $tokenId = $this->getRequest()->getParam('id');
  47. $userId = $this->getRequest()->getParam('user_id');
  48. $this->trustedManager->revokeTrustedDevice($tokenId);
  49. $this->messageManager->addSuccessMessage(__('Device authorization revoked'));
  50. return $this->_redirect('adminhtml/user/edit', ['user_id' => $userId]);
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. protected function _isAllowed()
  56. {
  57. return parent::_isAllowed() && $this->_authorization->isAllowed('MSP_TwoFactorAuth::tfa');
  58. }
  59. }