72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*
|
|
* https://www.d3data.de
|
|
*
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
* @link https://www.oxidmodule.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace D3\Totp\Modules\Application\Controller;
|
|
|
|
use D3\Totp\Application\Model\d3totp;
|
|
use D3\Totp\Application\Model\d3totp_conf;
|
|
use Doctrine\DBAL\Driver\Exception;
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
use OxidEsales\Eshop\Core\Session;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
trait d3_totp_getUserTrait
|
|
{
|
|
/**
|
|
* @return false|User
|
|
* @throws ContainerExceptionInterface
|
|
* @throws Exception
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws \Doctrine\DBAL\Exception
|
|
*/
|
|
public function getUser(): false|User
|
|
{
|
|
$user = parent::getUser();
|
|
|
|
if ($user && $user->isLoaded() && $user->getId()) {
|
|
$totp = $this->d3GetTotpObject();
|
|
$totp->loadByUserId($user->getId());
|
|
|
|
if ($totp->isActive()
|
|
&& !$this->d3TotpGetSessionObject()->getVariable(
|
|
isAdmin() ? d3totp_conf::SESSION_ADMIN_AUTH : d3totp_conf::SESSION_AUTH
|
|
)
|
|
) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* @return d3totp
|
|
*/
|
|
public function d3GetTotpObject(): d3totp
|
|
{
|
|
return oxNew(d3totp::class);
|
|
}
|
|
|
|
/**
|
|
* @return Session
|
|
*/
|
|
public function d3TotpGetSessionObject(): Session
|
|
{
|
|
return Registry::getSession();
|
|
}
|
|
}
|