BackendAuthUserLoginSuccess.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Observer;
  21. use Magento\Framework\Event\Observer;
  22. use Magento\Framework\Event\ObserverInterface;
  23. use MSP\TwoFactorAuth\Api\TfaInterface;
  24. use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
  25. class BackendAuthUserLoginSuccess implements ObserverInterface
  26. {
  27. /**
  28. * @var TrustedManagerInterface
  29. */
  30. private $trustedManager;
  31. /**
  32. * @var TfaInterface
  33. */
  34. private $tfa;
  35. public function __construct(
  36. TfaInterface $tfa,
  37. TrustedManagerInterface $trustedManager
  38. ) {
  39. $this->trustedManager = $trustedManager;
  40. $this->tfa = $tfa;
  41. }
  42. /**
  43. * @param Observer $observer
  44. * @return void
  45. * @SuppressWarnings("PHPMD.UnusedFormalParameter")
  46. */
  47. public function execute(Observer $observer)
  48. {
  49. if (!$this->tfa->isEnabled()) {
  50. return;
  51. }
  52. if ($this->trustedManager->isTrustedDevice()) {
  53. $this->trustedManager->rotateTrustedDeviceToken();
  54. }
  55. }
  56. }