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

71 lines
1.8 KiB
PHP
Raw Normal View History

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
*/
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();
}
}