2018-10-21 20:54:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-09-26 15:22:26 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2018-10-21 20:54:58 +02:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-09-26 15:22:26 +02:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2018-10-21 20:54:58 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-28 00:08:36 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-10-21 20:54:58 +02:00
|
|
|
namespace D3\Totp\Modules\Application\Controller\Admin;
|
|
|
|
|
2022-11-10 16:45:57 +01:00
|
|
|
use D3\TestingTools\Production\IsMockable;
|
2018-10-21 20:54:58 +02:00
|
|
|
use D3\Totp\Application\Model\d3totp;
|
2022-11-10 00:00:50 +01:00
|
|
|
use D3\Totp\Application\Model\d3totp_conf;
|
|
|
|
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
2018-10-21 20:54:58 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2019-08-07 23:51:48 +02:00
|
|
|
use OxidEsales\Eshop\Core\Session;
|
2018-10-21 20:54:58 +02:00
|
|
|
|
|
|
|
class d3_totp_LoginController extends d3_totp_LoginController_parent
|
|
|
|
{
|
2022-11-10 16:45:57 +01:00
|
|
|
use IsMockable;
|
|
|
|
|
2019-08-07 23:51:48 +02:00
|
|
|
/**
|
|
|
|
* @return d3totp
|
|
|
|
*/
|
|
|
|
public function d3GetTotpObject()
|
|
|
|
{
|
|
|
|
return oxNew(d3totp::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Session
|
|
|
|
*/
|
2022-11-09 11:27:11 +01:00
|
|
|
public function d3TotpGetSession()
|
2019-08-07 23:51:48 +02:00
|
|
|
{
|
|
|
|
return Registry::getSession();
|
|
|
|
}
|
|
|
|
|
2018-10-21 20:54:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed|string
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
*/
|
|
|
|
public function checklogin()
|
|
|
|
{
|
2022-11-10 16:45:57 +01:00
|
|
|
// parent::checklogin();
|
|
|
|
$return = $this->d3CallMockableParent('checklogin');
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2019-08-07 23:51:48 +02:00
|
|
|
$totp = $this->d3GetTotpObject();
|
2018-10-21 20:54:58 +02:00
|
|
|
$totp->loadByUserId(Registry::getSession()->getVariable("auth"));
|
|
|
|
|
2022-11-10 00:00:50 +01:00
|
|
|
if ($this->d3TotpLoginMissing($totp)) {
|
|
|
|
$userId = $this->d3TotpGetSession()->getVariable('auth');
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-10 00:00:50 +01:00
|
|
|
/** @var d3_totp_user $user */
|
2022-11-10 16:45:57 +01:00
|
|
|
$user = $this->d3TotpGetUserObject();
|
2022-11-10 00:00:50 +01:00
|
|
|
$user->logout();
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-10 00:00:50 +01:00
|
|
|
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, $userId);
|
|
|
|
return "d3totpadminlogin";
|
2022-09-28 00:08:36 +02:00
|
|
|
}
|
2019-07-28 23:34:39 +02:00
|
|
|
|
2022-11-10 00:00:50 +01:00
|
|
|
return $return;
|
2022-09-28 00:08:36 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 20:54:58 +02:00
|
|
|
/**
|
|
|
|
* @param d3totp $totp
|
|
|
|
* @return bool
|
2019-08-07 23:51:48 +02:00
|
|
|
*/
|
2022-11-10 00:00:50 +01:00
|
|
|
public function d3TotpLoginMissing($totp)
|
2019-08-07 23:51:48 +02:00
|
|
|
{
|
2022-11-10 00:00:50 +01:00
|
|
|
return $totp->isActive()
|
|
|
|
&& false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH);
|
2019-08-07 23:51:48 +02:00
|
|
|
}
|
2022-11-10 16:45:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3_totp_user
|
|
|
|
*/
|
|
|
|
protected function d3TotpGetUserObject(): d3_totp_user
|
|
|
|
{
|
|
|
|
return oxNew( User::class );
|
|
|
|
}
|
2022-09-30 21:06:30 +02:00
|
|
|
}
|