jsonFactory = $jsonFactory; $this->session = $session; $this->tfa = $tfa; $this->tfaSession = $tfaSession; $this->alert = $alert; $this->verification = $verification; $this->authy = $authy; } /** * Get current user * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * @inheritdoc */ public function execute() { $verificationCode = $this->getRequest()->getParam('tfa_verify'); $response = $this->jsonFactory->create(); try { $this->verification->verify($this->getUser(), $verificationCode); $this->authy->enroll($this->getUser()); $this->tfaSession->grantAccess(); $this->alert->event( 'MSP_TwoFactorAuth', 'Authy identity verified', AlertInterface::LEVEL_INFO, $this->getUser()->getUserName() ); $response->setData([ 'success' => true, ]); } catch (\Exception $e) { $this->alert->event( 'MSP_TwoFactorAuth', 'Authy identity verification failure', AlertInterface::LEVEL_ERROR, $this->getUser()->getUserName(), AlertInterface::ACTION_LOG, $e->getMessage() ); $response->setData([ 'success' => false, 'message' => $e->getMessage(), ]); } return $response; } /** * @inheritdoc */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), Authy::CODE) && !$this->tfa->getProvider(Authy::CODE)->isActive($user->getId()); } }