webauthn/src/Application/Controller/Traits/checkoutGetUserTrait.php

69 regels
1.7 KiB
PHP

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-11-02 12:03:38 +01:00
namespace D3\Webauthn\Application\Controller\Traits;
2022-10-24 22:24:40 +02:00
2022-10-29 00:45:11 +02:00
use D3\Webauthn\Application\Model\Webauthn;
2022-10-26 22:27:25 +02:00
use D3\Webauthn\Application\Model\WebauthnConf;
2022-10-31 23:17:04 +01:00
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception as DoctrineException;
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-31 23:17:04 +01:00
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
2022-10-24 22:24:40 +02:00
2022-11-02 12:03:38 +01:00
trait checkoutGetUserTrait
2022-10-24 22:24:40 +02:00
{
/**
2022-11-04 22:02:44 +01:00
* @return null|false|User
2022-10-31 23:17:04 +01:00
* @throws ContainerExceptionInterface
2022-11-02 12:03:38 +01:00
* @throws DoctrineException
* @throws Exception
2022-10-31 23:17:04 +01:00
* @throws NotFoundExceptionInterface
2022-10-24 22:24:40 +02:00
*/
2022-11-04 22:02:44 +01:00
public function getUser(): ?User
2022-10-24 22:24:40 +02:00
{
2022-10-29 00:45:11 +02:00
$user = parent::getUser();
2022-10-24 22:24:40 +02:00
2022-10-29 00:45:11 +02:00
if ($user && $user->getId()) {
2022-11-02 12:03:38 +01:00
$webauthn = $this->d3GetWebauthnObject();
2022-10-24 22:24:40 +02:00
2022-10-29 00:45:11 +02:00
if ($webauthn->isActive($user->getId())
2022-10-31 23:17:04 +01:00
&& !$this->d3GetSessionObject()->getVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH)
2022-10-24 22:24:40 +02:00
) {
return false;
}
}
2022-10-29 00:45:11 +02:00
return $user;
2022-10-24 22:24:40 +02:00
}
/**
2022-10-29 00:45:11 +02:00
* @return Webauthn
2022-10-24 22:24:40 +02:00
*/
2022-10-31 23:17:04 +01:00
public function d3GetWebauthnObject(): Webauthn
2022-10-24 22:24:40 +02:00
{
2022-10-29 00:45:11 +02:00
return oxNew(Webauthn::class);
2022-10-24 22:24:40 +02:00
}
/**
* @return Session
*/
2022-10-31 23:17:04 +01:00
public function d3GetSessionObject(): Session
2022-10-24 22:24:40 +02:00
{
return Registry::getSession();
}
}