devhelper/Application/Controller/d3dev.php

126 lines
4.9 KiB
PHP
Raw Normal View History

<?php
2024-09-04 08:58:40 +02:00
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* 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
*/
2018-02-23 11:06:24 +01:00
namespace D3\Devhelper\Application\Controller;
2024-07-03 09:32:01 +02:00
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
2018-02-23 12:30:57 +01:00
use D3\Devhelper\Modules\Application\Controller as ModuleController;
use D3\Devhelper\Modules\Core as ModuleCore;
2024-07-03 09:32:01 +02:00
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
2020-11-11 22:29:10 +01:00
use Exception;
2024-07-02 17:03:38 +02:00
use GuzzleHttp\Psr7\ServerRequest;
2018-02-23 11:06:24 +01:00
use OxidEsales\Eshop\Application\Controller\FrontendController;
2018-02-23 12:30:57 +01:00
use OxidEsales\Eshop\Application\Controller\ThankYouController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Email;
use OxidEsales\Eshop\Core\Exception\UserException;
use OxidEsales\Eshop\Core\Registry;
2024-07-02 17:03:38 +02:00
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
2024-07-03 09:32:01 +02:00
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
2018-02-23 11:06:24 +01:00
class d3dev extends FrontendController
{
public function init()
{
$this->_authenticate();
parent::init();
}
2024-09-04 08:58:40 +02:00
protected function _authenticate(): void
{
try {
2020-11-11 22:29:10 +01:00
$sUser = Registry::getRequest()->getRequestEscapedParameter('usr');
$sPassword = Registry::getRequest()->getRequestEscapedParameter('pwd');
2024-09-04 08:58:40 +02:00
if (!$sUser || !$sPassword) {
2024-07-02 17:03:38 +02:00
$request = ServerRequest::fromGlobals();
$sUser = $request->getServerParams()['PHP_AUTH_USER'];
$sPassword = $request->getServerParams()['PHP_AUTH_PW'];
}
2024-09-04 08:58:40 +02:00
if (!$sUser || !$sPassword) {
$sHttpAuthorization = $_REQUEST[ 'HTTP_AUTHORIZATION' ];
2024-09-04 08:58:40 +02:00
if ($sHttpAuthorization) {
$sUser = null;
$sPassword = null;
2024-09-04 08:58:40 +02:00
$aHttpAuthorization = explode(' ', $sHttpAuthorization);
if (is_array($aHttpAuthorization) && count($aHttpAuthorization) >= 2 && strtolower($aHttpAuthorization[ 0 ]) == 'basic') {
$sBasicAuthorization = base64_decode($aHttpAuthorization[ 1 ]);
$aBasicAuthorization = explode(':', $sBasicAuthorization);
if (is_array($aBasicAuthorization) && count($aBasicAuthorization) >= 2) {
$sUser = $aBasicAuthorization[ 0 ];
$sPassword = $aBasicAuthorization[ 1 ];
}
}
}
}
2024-07-02 17:03:38 +02:00
2024-09-04 08:58:40 +02:00
$oUser = oxNew(User::class);
if (!$sUser || !$sPassword || !$oUser->login($sUser, $sPassword)) {
throw oxNew(UserException::class, 'EXCEPTION_USER_NOVALIDLOGIN');
}
2024-09-04 08:58:40 +02:00
} catch (Exception) {
$oShop = Registry::getConfig()->getActiveShop();
2024-09-04 08:58:40 +02:00
header('WWW-Authenticate: Basic realm="' . $oShop->getFieldData('oxname') . '"');
2024-07-02 17:03:38 +02:00
http_response_code(401);
2024-09-04 08:58:40 +02:00
exit(1);
}
}
/**
2024-07-03 09:32:01 +02:00
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws DBALDriverException
*/
2024-07-03 09:32:01 +02:00
public function showOrderMailContent(): void
{
2024-07-03 09:32:01 +02:00
try {
2024-09-04 08:58:40 +02:00
header('Content-type: text/html; charset=' . Registry::getLang()->translateString('charset'));
2024-07-03 09:32:01 +02:00
/** @var ModuleSettingService $moduleSettingService */
2024-09-04 08:58:40 +02:00
$moduleSettingService = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
2024-09-04 08:58:40 +02:00
if (Registry::getConfig()->getActiveShop()->isProductiveMode() ||
! $moduleSettingService->getBoolean(ModuleCore\d3_dev_conf::OPTION_SHOWMAILSINBROWSER, 'd3dev')
2024-07-03 09:32:01 +02:00
) {
throw oxNew(UnauthorisedException::class);
}
2024-09-04 08:58:40 +02:00
$sTpl = Registry::getRequest()->getRequestEscapedParameter('type');
2024-07-03 09:32:01 +02:00
/** @var ModuleController\d3_dev_thankyou $oThankyou */
2024-09-04 08:58:40 +02:00
$oThankyou = oxNew(ThankYouController::class);
2024-07-03 09:32:01 +02:00
$oOrder = $oThankyou->d3GetLastOrder();
2024-07-03 09:32:01 +02:00
/** @var ModuleCore\d3_dev_oxemail $oEmail */
2024-09-04 08:58:40 +02:00
$oEmail = oxNew(Email::class);
echo $oEmail->d3GetOrderMailContent($oOrder, $sTpl);
http_response_code(200);
2024-07-03 09:32:01 +02:00
} catch (UnauthorisedException $exception) {
echo $exception->getMessage();
http_response_code(401);
} catch (Exception $exception) {
echo $exception->getMessage();
http_response_code(500);
2024-07-03 09:32:01 +02:00
} finally {
Registry::getConfig()->pageClose();
die();
}
}
}