8
0
Fork 1
oxtotp/src/Modules/Application/Controller/Admin/d3_totp_LoginController.php

130 Zeilen
4.0 KiB
PHP

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;
2022-11-25 15:42:33 +01:00
use OxidEsales\Eshop\Core\Language;
2018-10-21 20:54:58 +02:00
use OxidEsales\Eshop\Core\Registry;
2019-08-07 23:51:48 +02:00
use OxidEsales\Eshop\Core\Session;
2022-11-25 15:42:33 +01:00
use OxidEsales\Eshop\Core\UtilsServer;
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
*/
2022-11-25 15:42:33 +01:00
public function d3GetTotpObject(): d3totp
2019-08-07 23:51:48 +02:00
{
return oxNew(d3totp::class);
}
/**
* @return Session
*/
2022-11-25 15:42:33 +01:00
public function d3TotpGetSession(): Session
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 23:52:16 +01:00
$this->d3TotpGetSession()->setVariable(
d3totp_conf::SESSION_ADMIN_PROFILE,
Registry::getRequest()->getRequestEscapedParameter('profile')
);
2022-11-24 23:52:16 +01:00
$this->d3TotpGetSession()->setVariable(
d3totp_conf::SESSION_ADMIN_CHLANGUAGE,
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
);
return $this->d3CallMockableFunction([d3_totp_LoginController_parent::class, 'checklogin']);
}
2018-10-21 20:54:58 +02:00
public function d3totpAfterLogin()
{
2022-11-24 23:52:16 +01:00
$myUtilsServer = $this->d3TotpGetUtilsServer();
$sProfile = $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_PROFILE);
2018-10-21 20:54:58 +02:00
// #533
if (isset($sProfile)) {
2022-11-24 23:52:16 +01:00
$aProfiles = $this->d3TotpGetSession()->getVariable("aAdminProfiles");
if ($aProfiles && isset($aProfiles[$sProfile])) {
// setting cookie to store last locally used profile
$myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000, "/");
2022-11-24 23:52:16 +01:00
$this->d3TotpGetSession()->setVariable("profile", $aProfiles[$sProfile]);
$this->d3TotpGetSession()->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();
2022-11-24 23:52:16 +01:00
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE);
2022-11-24 20:27:07 +01:00
}
public function d3totpAfterLoginSetLanguage()
{
2022-11-24 23:52:16 +01:00
$myUtilsServer = $this->d3TotpGetUtilsServer();
$iLang = $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE);
2018-10-21 20:54:58 +02:00
2022-11-24 23:52:16 +01:00
$aLanguages = $this->d3TotpGetLangObject()->getAdminTplLanguageArray();
if (!isset($aLanguages[$iLang])) {
$iLang = key($aLanguages);
2022-09-28 00:08:36 +02:00
}
$myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000, "/");
2022-11-25 20:24:09 +01:00
$this->d3TotpGetLangObject()->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()
&& 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
/**
2022-11-25 15:42:33 +01:00
* @return UtilsServer
2022-11-10 16:45:57 +01:00
*/
2022-11-25 15:42:33 +01:00
protected function d3TotpGetUtilsServer(): UtilsServer
2022-11-24 23:52:16 +01:00
{
return Registry::getUtilsServer();
}
/**
2022-11-25 15:42:33 +01:00
* @return Language
2022-11-24 23:52:16 +01:00
*/
2022-11-25 15:42:33 +01:00
protected function d3TotpGetLangObject(): Language
2022-11-24 23:52:16 +01:00
{
return Registry::getLang();
}
2022-09-30 21:06:30 +02:00
}