session = $session; $this->jsonFactory = $jsonFactory; $this->tfa = $tfa; $this->trustedManager = $trustedManager; $this->tfaSession = $tfaSession; $this->alert = $alert; $this->oneTouch = $oneTouch; } /** * Get current user * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * @inheritdoc */ public function execute() { $result = $this->jsonFactory->create(); try { $res = $this->oneTouch->verify($this->getUser()); if ($res == 'approved') { $this->trustedManager->handleTrustDeviceRequest(Authy::CODE, $this->getRequest()); $this->tfaSession->grantAccess(); $res = ['success' => true, 'status' => 'approved']; } else { $res = ['success' => false, 'status' => $res]; if ($res == 'denied') { $this->alert->event( 'MSP_TwoFactorAuth', 'Authy onetouch auth denied', AlertInterface::LEVEL_WARNING, $this->getUser()->getUserName() ); } } } catch (\Exception $e) { $result->setHttpResponseCode(500); $res = ['success' => false, 'message' => $e->getMessage()]; $this->alert->event( 'MSP_TwoFactorAuth', 'Authy onetouch error', AlertInterface::LEVEL_ERROR, $this->getUser()->getUserName(), AlertInterface::ACTION_LOG, $e->getMessage() ); } $result->setData($res); return $result; } /** * @inheritdoc */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), Authy::CODE) && $this->tfa->getProvider(Authy::CODE)->isActive($user->getId()); } }