![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-two-factor-auth/Controller/Adminhtml/Authy/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\TwoFactorAuth\Controller\Adminhtml\Authy; use Exception; use Magento\Backend\Model\Auth\Session; use Magento\Backend\App\Action; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\Controller\Result\JsonFactory; use Magento\TwoFactorAuth\Api\TfaInterface; use Magento\TwoFactorAuth\Controller\Adminhtml\AbstractAction; use Magento\TwoFactorAuth\Model\Provider\Engine\Authy; use Magento\User\Model\User; /** * Verify with authy token * * @SuppressWarnings(PHPMD.CamelCaseMethodName) */ class Token extends AbstractAction implements HttpGetActionInterface, HttpPostActionInterface { /** * @var Session */ private $session; /** * @var JsonFactory */ private $jsonFactory; /** * @var TfaInterface */ private $tfa; /** * @var Authy\Token */ private $token; /** * @param Action\Context $context * @param JsonFactory $jsonFactory * @param TfaInterface $tfa * @param Authy\Token $token * @param Session $session */ public function __construct( Action\Context $context, JsonFactory $jsonFactory, TfaInterface $tfa, Authy\Token $token, Session $session ) { parent::__construct($context); $this->session = $session; $this->jsonFactory = $jsonFactory; $this->tfa = $tfa; $this->token = $token; } /** * Get current user * * @return User|null */ private function getUser(): ?User { return $this->session->getUser(); } /** * @inheritdoc */ public function execute() { $via = $this->getRequest()->getParam('via'); $result = $this->jsonFactory->create(); try { $this->token->request($this->getUser(), $via); $res = ['success' => true]; } catch (Exception $e) { $result->setHttpResponseCode(500); $res = ['success' => false, 'message' => $e->getMessage()]; } $result->setData($res); return $result; } /** * @inheritdoc */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed((int) $user->getId(), Authy::CODE) && $this->tfa->getProvider(Authy::CODE)->isActive((int) $user->getId()); } }