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-24 00:51:56 +01:00
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
d3totp_conf::SESSION_ADMIN_PROFILE,
|
|
|
|
Registry::getRequest()->getRequestEscapedParameter('profile')
|
|
|
|
);
|
|
|
|
Registry::getSession()->setVariable(
|
|
|
|
d3totp_conf::SESSION_ADMIN_CHLANGUAGE,
|
|
|
|
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
|
|
|
|
);
|
|
|
|
|
2022-11-10 16:45:57 +01:00
|
|
|
// parent::checklogin();
|
2022-11-24 00:51:56 +01:00
|
|
|
return $this->d3CallMockableParent('checklogin');
|
|
|
|
}
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-24 00:51:56 +01:00
|
|
|
public function d3totpAfterLogin()
|
|
|
|
{
|
|
|
|
$myUtilsServer = Registry::getUtilsServer();
|
|
|
|
$sProfile = Registry::getSession()->getVariable(d3totp_conf::SESSION_ADMIN_PROFILE);
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-24 00:51:56 +01:00
|
|
|
// #533
|
|
|
|
if (isset($sProfile)) {
|
|
|
|
$aProfiles = Registry::getSession()->getVariable("aAdminProfiles");
|
|
|
|
if ($aProfiles && isset($aProfiles[$sProfile])) {
|
|
|
|
// setting cookie to store last locally used profile
|
|
|
|
$myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000, "/");
|
|
|
|
Registry::getSession()->setVariable("profile", $aProfiles[$sProfile]);
|
|
|
|
Registry::getSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_PROFILE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//deleting cookie info, as setting profile to default
|
|
|
|
$myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600, "/");
|
|
|
|
}
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-24 20:27:07 +01:00
|
|
|
$this->d3totpAfterLoginSetLanguage();
|
|
|
|
Registry::getSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function d3totpAfterLoginSetLanguage()
|
|
|
|
{
|
|
|
|
$myUtilsServer = Registry::getUtilsServer();
|
2022-11-24 00:51:56 +01:00
|
|
|
$iLang = Registry::getSession()->getVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE);
|
2018-10-21 20:54:58 +02:00
|
|
|
|
2022-11-24 00:51:56 +01:00
|
|
|
$aLanguages = Registry::getLang()->getAdminTplLanguageArray();
|
|
|
|
if (!isset($aLanguages[$iLang])) {
|
|
|
|
$iLang = key($aLanguages);
|
2022-09-28 00:08:36 +02:00
|
|
|
}
|
2019-07-28 23:34:39 +02:00
|
|
|
|
2022-11-24 00:51:56 +01:00
|
|
|
$myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/");
|
|
|
|
Registry::getLang()->setTplLanguage($iLang);
|
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()
|
2022-11-23 09:21:52 +01:00
|
|
|
&& false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_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
|
|
|
}
|