2022-10-24 22:24:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-11-04 22:45:47 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2022-10-24 22:24:40 +02:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-11-04 22:45:47 +01:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
namespace D3\Webauthn\Modules\Application\Component;
|
|
|
|
|
2022-10-26 22:27:25 +02:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
2022-10-31 23:17:04 +01:00
|
|
|
use D3\Webauthn\Modules\Application\Model\d3_User_Webauthn;
|
2022-10-31 00:11:06 +01:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
|
2022-10-29 00:19:34 +02:00
|
|
|
use Doctrine\DBAL\Exception;
|
2022-10-24 22:24:40 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\Session;
|
2022-10-29 00:19:34 +02:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
class d3_webauthn_UserComponent extends d3_webauthn_UserComponent_parent
|
|
|
|
{
|
|
|
|
/**
|
2022-11-08 22:47:11 +01:00
|
|
|
* @return string
|
2022-10-31 00:11:06 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws Exception
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
2022-11-08 22:47:11 +01:00
|
|
|
public function login()
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-10-26 22:27:25 +02:00
|
|
|
$lgn_user = Registry::getRequest()->getRequestParameter('lgn_usr');
|
2022-11-02 16:38:43 +01:00
|
|
|
$password = Registry::getRequest()->getRequestParameter('lgn_pwd');
|
2022-10-31 23:17:04 +01:00
|
|
|
/** @var d3_User_Webauthn $user */
|
|
|
|
$user = oxNew(User::class);
|
|
|
|
$userId = $user->d3GetLoginUserId($lgn_user);
|
2022-10-26 22:27:25 +02:00
|
|
|
|
2022-11-08 22:19:45 +01:00
|
|
|
if ($lgn_user && $userId && !strlen(trim((string) $password))) {
|
2022-10-24 22:24:40 +02:00
|
|
|
$webauthn = $this->d3GetWebauthnObject();
|
2022-10-28 00:45:32 +02:00
|
|
|
|
2022-10-26 22:27:25 +02:00
|
|
|
if ($webauthn->isActive($userId)
|
2022-10-31 00:11:06 +01:00
|
|
|
&& !Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH)
|
2022-10-24 22:24:40 +02:00
|
|
|
) {
|
|
|
|
Registry::getSession()->setVariable(
|
2022-10-26 22:27:25 +02:00
|
|
|
WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS,
|
2022-10-24 22:24:40 +02:00
|
|
|
$this->getParent()->getClassKey() != 'd3webauthnlogin' ? $this->getParent()->getClassKey() : 'start');
|
2022-10-31 00:11:06 +01:00
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER,
|
|
|
|
$userId
|
|
|
|
);
|
2022-11-02 22:31:49 +01:00
|
|
|
|
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
WebauthnConf::WEBAUTHN_SESSION_NAVPARAMS,
|
|
|
|
$this->getParent()->getNavigationParams()
|
|
|
|
);
|
2022-10-24 22:24:40 +02:00
|
|
|
Registry::getSession()->setVariable(
|
2022-10-26 22:27:25 +02:00
|
|
|
WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS,
|
2022-10-24 22:24:40 +02:00
|
|
|
$this->getParent()->getViewConfig()->getNavFormParams()
|
|
|
|
);
|
|
|
|
|
2022-11-09 11:21:09 +01:00
|
|
|
$sUrl = Registry::getConfig()->getShopHomeUrl() . 'cl=d3webauthnlogin';
|
2022-11-08 22:47:11 +01:00
|
|
|
Registry::getUtils()->redirect($sUrl, true, 302);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 22:47:11 +01:00
|
|
|
return parent::login();
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-26 22:27:25 +02:00
|
|
|
* @return Webauthn
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
2022-10-31 00:11:06 +01:00
|
|
|
public function d3GetWebauthnObject(): Webauthn
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-10-26 22:27:25 +02:00
|
|
|
return oxNew(Webauthn::class);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
public function d3CancelWebauthnLogin(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
$this->d3WebauthnClearSessionVariables();
|
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function d3WebauthnClearSessionVariables(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-11-09 11:21:09 +01:00
|
|
|
$this->d3WebauthnGetSession()->deleteVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
|
|
|
|
$this->d3WebauthnGetSession()->deleteVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
|
|
|
|
$this->d3WebauthnGetSession()->deleteVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS);
|
|
|
|
$this->d3WebauthnGetSession()->deleteVariable(WebauthnConf::WEBAUTHN_LOGIN_OBJECT);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Session
|
|
|
|
*/
|
2022-11-09 11:21:09 +01:00
|
|
|
public function d3WebauthnGetSession(): Session
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
return Registry::getSession();
|
|
|
|
}
|
|
|
|
}
|