webauthn/src/Application/Model/WebauthnAfterLogin.php

81 lines
2.7 KiB
PHP
Raw Normal View History

<?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\Webauthn\Application\Model;
use D3\TestingTools\Production\IsMockable;
2022-12-09 22:23:32 +01:00
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\UtilsServer;
class WebauthnAfterLogin
{
use IsMockable;
2022-12-09 22:23:32 +01:00
/**
* @return void
*/
public function setDisplayProfile(): void
{
2022-12-09 22:23:32 +01:00
$session = $this->d3GetMockableRegistryObject(Session::class);
2022-12-09 22:23:32 +01:00
$sProfile = $this->d3GetMockableRegistryObject(Request::class)
->getRequestEscapedParameter('profile') ?:
$session->getVariable(WebauthnConf::WEBAUTHN_ADMIN_PROFILE);
$session->deleteVariable(WebauthnConf::WEBAUTHN_ADMIN_PROFILE);
$myUtilsServer = $this->d3GetMockableRegistryObject(UtilsServer::class);
if (isset($sProfile)) {
2022-12-09 22:23:32 +01:00
$aProfiles = $session->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-12-09 22:23:32 +01:00
$session->setVariable("profile", $aProfiles[$sProfile]);
}
} else {
//deleting cookie info, as setting profile to default
$myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600);
}
}
/**
* @return void
*/
2022-12-09 22:23:32 +01:00
public function changeLanguage(): void
{
$myUtilsServer = $this->d3GetMockableRegistryObject(UtilsServer::class);
2022-12-09 22:23:32 +01:00
$session = $this->d3GetMockableRegistryObject(Session::class);
// languages
2022-12-09 22:23:32 +01:00
$iLang = $this->d3GetMockableRegistryObject(Request::class)
->getRequestEscapedParameter('chlanguage') ?:
$session->getVariable(WebauthnConf::WEBAUTHN_ADMIN_CHLANGUAGE);
$session->deleteVariable(WebauthnConf::WEBAUTHN_ADMIN_CHLANGUAGE);
2022-12-09 22:23:32 +01:00
$language = $this->d3GetMockableRegistryObject(Language::class);
$aLanguages = $language->getAdminTplLanguageArray();
if (!isset($aLanguages[$iLang])) {
$iLang = key($aLanguages);
}
$myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000);
2022-12-09 22:23:32 +01:00
$language->setTplLanguage($iLang);
}
}