tfa = $tfa; $this->session = $session; $this->pageFactory = $pageFactory; $this->tfaSession = $tfaSession; $this->duoSecurity = $duoSecurity; $this->dataObjectFactory = $dataObjectFactory; $this->alert = $alert; $this->context = $context; } /** * Get current user * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * @inheritdoc */ public function execute() { $user = $this->getUser(); if ($this->duoSecurity->verify($user, $this->dataObjectFactory->create([ 'data' => $this->getRequest()->getParams(), ]))) { $this->tfa->getProvider(DuoSecurity::CODE)->activate($user->getId()); $this->tfaSession->grantAccess(); return $this->_redirect($this->context->getBackendUrl()->getStartupPageUrl()); } else { $this->alert->event( 'MSP_TwoFactorAuth', 'DuoSecurity invalid auth', AlertInterface::LEVEL_WARNING, $user->getUserName() ); return $this->_redirect('*/*/auth'); } } /** * Check if admin has permissions to visit related pages * * @return bool */ protected function _isAllowed() { // Do not check for activation $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), DuoSecurity::CODE); } }