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\Modules\Application\Controller\Admin;
|
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
2022-10-26 22:27:25 +02:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
2022-10-29 00:19:34 +02:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineException;
|
|
|
|
use Doctrine\DBAL\Exception;
|
|
|
|
use Doctrine\DBAL\Query\QueryBuilder;
|
2022-10-24 22:24:40 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\Session;
|
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2022-10-29 00:19:34 +02:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
class d3_LoginController_Webauthn extends d3_LoginController_Webauthn_parent
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-10-29 00:19:34 +02:00
|
|
|
* @return Webauthn
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
2022-10-29 00:19:34 +02:00
|
|
|
public function d3GetWebauthnObject(): Webauthn
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-10-29 00:19:34 +02:00
|
|
|
return oxNew(Webauthn::class);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed|string
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
*/
|
|
|
|
public function checklogin()
|
|
|
|
{
|
2022-10-29 00:19:34 +02:00
|
|
|
$lgn_user = Registry::getRequest()->getRequestParameter('user');
|
|
|
|
$userId = $this->d3GetLoginUserId($lgn_user);
|
2022-10-24 22:24:40 +02:00
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
if ($lgn_user && $userId && false === Registry::getSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH)) {
|
|
|
|
$webauthn = $this->d3GetWebauthnObject();
|
2022-10-24 22:24:40 +02:00
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
if ($webauthn->isActive($userId)
|
|
|
|
&& false == Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH)
|
|
|
|
) {
|
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS,
|
|
|
|
$this->getClassKey() != 'd3webauthnadminlogin' ? $this->getClassKey() : 'admin_start');
|
|
|
|
Registry::getSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER, $userId);
|
|
|
|
Registry::getSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_LOGINUSER, $lgn_user);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS,
|
|
|
|
$this->getViewConfig()->getNavFormParams()
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
//$oUser->d3templogout();
|
|
|
|
|
|
|
|
return "d3webauthnadminlogin";
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
return parent::checklogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $username
|
|
|
|
* @return string|null
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws Exception
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
protected function d3GetLoginUserId($username): ?string
|
|
|
|
{
|
|
|
|
if (empty($username)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = oxNew(User::class);
|
|
|
|
|
|
|
|
/** @var QueryBuilder $qb */
|
|
|
|
$qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
|
|
|
$qb->select('oxid')
|
|
|
|
->from($user->getViewName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->and(
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxusername',
|
|
|
|
$qb->createNamedParameter($username)
|
|
|
|
),
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxshopid',
|
|
|
|
$qb->createNamedParameter(Registry::getConfig()->getShopId())
|
|
|
|
),
|
|
|
|
$qb->expr()->eq(
|
|
|
|
'oxrights',
|
|
|
|
$qb->createNamedParameter('malladmin')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)->setMaxResults(1);
|
|
|
|
|
|
|
|
return $qb->execute()->fetchOne();
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function d3WebauthnCancelLogin()
|
|
|
|
{
|
|
|
|
$oUser = $this->d3GetUserObject();
|
|
|
|
$oUser->logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function d3GetUserObject()
|
|
|
|
{
|
|
|
|
return oxNew(User::class);
|
|
|
|
}
|
|
|
|
}
|