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\Controller\Admin;
|
|
|
|
|
2022-12-03 00:33:46 +01:00
|
|
|
use D3\TestingTools\Production\IsMockable;
|
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-31 23:17:04 +01:00
|
|
|
use D3\Webauthn\Modules\Application\Model\d3_User_Webauthn;
|
2022-10-29 00:19:34 +02:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineException;
|
|
|
|
use Doctrine\DBAL\Exception;
|
2022-10-24 22:24:40 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
2022-12-02 15:56:17 +01:00
|
|
|
use OxidEsales\Eshop\Core\Request;
|
2022-12-03 00:33:46 +01:00
|
|
|
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_LoginController_Webauthn extends d3_LoginController_Webauthn_parent
|
|
|
|
{
|
2022-12-03 00:33:46 +01:00
|
|
|
use IsMockable;
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
/**
|
|
|
|
* @return mixed|string
|
2022-10-31 00:11:06 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws Exception
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
|
|
|
public function checklogin()
|
|
|
|
{
|
2022-12-04 00:24:28 +01:00
|
|
|
$lgn_user = $this->d3GetMockableRegistryObject(Request::class)->getRequestParameter( 'user') ?:
|
|
|
|
$this->d3GetMockableRegistryObject(Session::class)
|
|
|
|
->getVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_LOGINUSER);
|
2022-10-24 22:24:40 +02:00
|
|
|
|
2022-10-31 23:17:04 +01:00
|
|
|
/** @var d3_User_Webauthn $user */
|
2022-12-04 00:24:28 +01:00
|
|
|
$user = $this->d3GetMockableOxNewObject(User::class);
|
2022-10-31 23:17:04 +01:00
|
|
|
$userId = $user->d3GetLoginUserId($lgn_user, 'malladmin');
|
|
|
|
|
2022-12-02 15:56:17 +01:00
|
|
|
if ( $this->d3CanUseWebauthn( $lgn_user, $userId)) {
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Session::class)->setVariable(
|
2022-11-24 01:02:20 +01:00
|
|
|
WebauthnConf::WEBAUTHN_ADMIN_PROFILE,
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Request::class)
|
|
|
|
->getRequestEscapedParameter( 'profile')
|
2022-11-24 01:02:20 +01:00
|
|
|
);
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Session::class)->setVariable(
|
2022-11-24 01:02:20 +01:00
|
|
|
WebauthnConf::WEBAUTHN_ADMIN_CHLANGUAGE,
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Request::class)
|
|
|
|
->getRequestEscapedParameter( 'chlanguage')
|
2022-11-24 01:02:20 +01:00
|
|
|
);
|
|
|
|
|
2022-12-03 00:33:46 +01:00
|
|
|
if ($this->hasWebauthnButNotLoggedin($userId)) {
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Session::class)->setVariable(
|
2022-11-23 08:46:25 +01:00
|
|
|
WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTCLASS,
|
2022-10-31 00:11:06 +01:00
|
|
|
$this->getClassKey() != 'd3webauthnadminlogin' ? $this->getClassKey() : 'admin_start'
|
|
|
|
);
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Session::class)->setVariable(
|
2022-11-23 08:46:25 +01:00
|
|
|
WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTUSER,
|
2022-10-31 00:11:06 +01:00
|
|
|
$userId
|
|
|
|
);
|
2022-12-04 00:24:28 +01:00
|
|
|
$this->d3GetMockableRegistryObject(Session::class)->setVariable(
|
2022-11-23 08:46:25 +01:00
|
|
|
WebauthnConf::WEBAUTHN_ADMIN_SESSION_LOGINUSER,
|
2022-10-31 00:11:06 +01:00
|
|
|
$lgn_user
|
|
|
|
);
|
2022-10-29 00:19:34 +02:00
|
|
|
|
|
|
|
return "d3webauthnadminlogin";
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 00:33:46 +01:00
|
|
|
return $this->d3CallMockableParent('checklogin');
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function d3WebauthnCancelLogin(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-12-04 00:24:28 +01:00
|
|
|
$user = $this->d3GetMockableOxNewObject(User::class);
|
|
|
|
$user->logout();
|
2022-12-03 00:33:46 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 15:56:17 +01:00
|
|
|
/**
|
|
|
|
* @param $lgn_user
|
|
|
|
* @param string|null $userId
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function d3CanUseWebauthn( $lgn_user, ?string $userId): bool
|
|
|
|
{
|
2022-12-04 00:24:28 +01:00
|
|
|
$password = $this->d3GetMockableRegistryObject(Request::class)->getRequestParameter( 'pwd');
|
2022-12-02 15:56:17 +01:00
|
|
|
|
|
|
|
return $lgn_user &&
|
|
|
|
$userId &&
|
2022-12-04 00:24:28 +01:00
|
|
|
false === $this->d3GetMockableRegistryObject(Session::class)
|
|
|
|
->hasVariable( WebauthnConf::WEBAUTHN_ADMIN_SESSION_AUTH ) &&
|
2022-12-02 15:56:17 +01:00
|
|
|
( ! strlen( trim( (string) $password ) ) );
|
|
|
|
}
|
2022-12-03 00:33:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $userId
|
|
|
|
* @return bool
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
protected function hasWebauthnButNotLoggedin($userId): bool
|
|
|
|
{
|
2022-12-04 00:24:28 +01:00
|
|
|
$webauthn = $this->d3GetMockableOxNewObject(Webauthn::class);
|
2022-12-03 00:33:46 +01:00
|
|
|
|
|
|
|
return $webauthn->isActive($userId)
|
2022-12-04 00:24:28 +01:00
|
|
|
&& !$this->d3GetMockableRegistryObject(Session::class)
|
|
|
|
->getVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_AUTH);
|
2022-12-03 00:33:46 +01:00
|
|
|
}
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|