2022-10-24 22:24:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Webauthn\Application\Controller;
|
|
|
|
|
2022-10-28 00:45:32 +02:00
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
2022-10-26 22:27:25 +02:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
2022-11-03 13:18:02 +01:00
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
|
2022-10-31 23:17:04 +01:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
|
2022-10-31 00:11:06 +01:00
|
|
|
use Doctrine\DBAL\Exception as DoctrineException;
|
2022-10-24 22:24:40 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\Utils;
|
2022-10-31 00:11:06 +01:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
class d3webauthnlogin extends FrontendController
|
|
|
|
{
|
|
|
|
protected $_sThisTemplate = 'd3webauthnlogin.tpl';
|
|
|
|
|
2022-11-02 22:31:49 +01:00
|
|
|
public function getNavigationParams()
|
|
|
|
{
|
|
|
|
$navparams = Registry::getSession()->getVariable(
|
|
|
|
WebauthnConf::WEBAUTHN_SESSION_NAVPARAMS
|
|
|
|
);
|
|
|
|
|
|
|
|
return array_merge(
|
|
|
|
$navparams,
|
|
|
|
['cl' => $navparams['actcontrol']]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
/**
|
|
|
|
* @return null
|
2022-10-31 23:17:04 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
2022-10-26 22:27:25 +02:00
|
|
|
if (Registry::getSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH) ||
|
2022-10-30 00:27:11 +02:00
|
|
|
!Registry::getSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER)
|
2022-10-24 22:24:40 +02:00
|
|
|
) {
|
2022-10-30 00:27:11 +02:00
|
|
|
$this->getUtils()->redirect('index.php?cl=start');
|
|
|
|
if (!defined('OXID_PHP_UNIT')) {
|
2022-10-24 22:24:40 +02:00
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
exit;
|
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->generateCredentialRequest();
|
|
|
|
|
2022-10-26 22:27:25 +02:00
|
|
|
$this->addTplParam('navFormParams', Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
return parent::render();
|
|
|
|
}
|
|
|
|
|
2022-10-31 00:11:06 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
2022-10-31 23:17:04 +01:00
|
|
|
* @throws DoctrineDriverException
|
2022-10-31 00:11:06 +01:00
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
2022-10-24 22:24:40 +02:00
|
|
|
public function generateCredentialRequest()
|
|
|
|
{
|
2022-11-03 13:18:02 +01:00
|
|
|
$userId = Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
|
|
|
|
|
2022-10-31 00:11:06 +01:00
|
|
|
try {
|
|
|
|
/** @var Webauthn $webauthn */
|
|
|
|
$webauthn = oxNew(Webauthn::class);
|
|
|
|
$publicKeyCredentialRequestOptions = $webauthn->getRequestOptions($userId);
|
|
|
|
$this->addTplParam('webauthn_publickey_login', $publicKeyCredentialRequestOptions);
|
2022-11-04 08:38:08 +01:00
|
|
|
$this->addTplParam('isAdmin', isAdmin());
|
2022-10-31 00:11:06 +01:00
|
|
|
} catch (WebauthnException $e) {
|
2022-10-31 23:17:04 +01:00
|
|
|
Registry::getSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
|
2022-11-04 00:12:42 +01:00
|
|
|
Registry::getLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
|
2022-11-04 00:05:52 +01:00
|
|
|
Registry::getLogger()->debug($e->getTraceAsString());
|
2022-11-03 13:18:02 +01:00
|
|
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
2022-10-31 23:17:04 +01:00
|
|
|
$this->getUtils()->redirect('index.php?cl=start');
|
2022-10-31 00:11:06 +01:00
|
|
|
}
|
2022-10-28 00:45:32 +02:00
|
|
|
}
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
/**
|
|
|
|
* @return Utils
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getUtils(): Utils
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
return Registry::getUtils();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPreviousClass()
|
|
|
|
{
|
2022-10-26 22:27:25 +02:00
|
|
|
return Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 00:27:11 +02:00
|
|
|
public function previousClassIsOrderStep(): bool
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-10-26 22:27:25 +02:00
|
|
|
$sClassKey = Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
|
2022-10-24 22:24:40 +02:00
|
|
|
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
|
2022-10-30 00:27:11 +02:00
|
|
|
$resolvedClass = $resolvedClass ?: 'start';
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
/** @var FrontendController $oController */
|
|
|
|
$oController = oxNew($resolvedClass);
|
|
|
|
return $oController->getIsOrderStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getIsOrderStep(): bool
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
return $this->previousClassIsOrderStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns Bread Crumb - you are here page1/page2/page3...
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getBreadCrumb(): array
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
$aPaths = [];
|
|
|
|
$aPath = [];
|
|
|
|
$iBaseLanguage = Registry::getLang()->getBaseLanguage();
|
|
|
|
$aPath['title'] = Registry::getLang()->translateString('D3_WEBAUTHN_BREADCRUMB', $iBaseLanguage, false);
|
|
|
|
$aPath['link'] = $this->getLink();
|
|
|
|
|
|
|
|
$aPaths[] = $aPath;
|
|
|
|
|
|
|
|
return $aPaths;
|
|
|
|
}
|
|
|
|
}
|