devhelper/Modules/Application/Controller/d3_dev_thankyou.php

182 regels
6.1 KiB
PHP

<?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\Modules\Application\Controller;
// .../?cl=thankyou[&d3orderid=23]
2024-07-03 09:32:01 +02:00
use D3\Devhelper\Application\Model\Exception\NoOrderFoundException;
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
2018-02-23 12:30:57 +01:00
use D3\Devhelper\Modules\Application\Model\d3_dev_oxorder;
2020-11-11 22:29:10 +01:00
use D3\Devhelper\Modules\Core\d3_dev_conf;
2024-07-03 09:32:01 +02:00
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Doctrine\DBAL\Exception as DBALException;
2020-11-11 22:29:10 +01:00
use Exception;
2018-02-23 12:30:57 +01:00
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\UserException;
use OxidEsales\Eshop\Core\Registry;
2024-07-03 09:32:01 +02:00
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3_dev_thankyou extends d3_dev_thankyou_parent
{
/**
2018-02-23 12:30:57 +01:00
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public function init()
{
$sSessChallenge = Registry::getSession()->getVariable('sess_challenge');
parent::init();
2020-11-11 22:29:10 +01:00
if (Registry::getRequest()->getRequestEscapedParameter("d3dev")
2024-07-03 09:32:01 +02:00
&& !Registry::getConfig()->getActiveShop()->isProductiveMode()
2020-11-11 22:29:10 +01:00
&& Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_PREVENTDELBASKET)
) {
2024-09-04 08:58:40 +02:00
Registry::getSession()->setVariable('sess_challenge', $sSessChallenge);
}
2020-11-11 22:29:10 +01:00
if ($this->d3DevCanShowThankyou()) {
$this->_d3authenticate();
$oOrder = $this->d3GetLastOrder();
2020-11-11 22:29:10 +01:00
$this->_oBasket = $oOrder->d3DevGetOrderBasket();
}
}
2020-11-11 22:29:10 +01:00
/**
* @return bool
*/
public function d3DevCanShowThankyou()
{
2024-07-03 09:32:01 +02:00
return Registry::getRequest()->getRequestEscapedParameter("d3dev") &&
!Registry::getConfig()->getActiveShop()->isProductiveMode() &&
Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_SHOWTHANKYOU);
2020-11-11 22:29:10 +01:00
}
/**
* @return string
*/
public function render()
{
2020-11-11 23:59:40 +01:00
$currentClass = '';
2020-11-11 22:29:10 +01:00
if ($this->d3DevCanShowThankyou()) {
$currentClass = $this->getViewConfig()->getViewConfigParam('cl');
}
$ret = parent::render();
if ($this->d3DevCanShowThankyou()) {
$this->getViewConfig()->setViewConfigParam('cl', $currentClass);
}
return $ret;
}
2024-09-04 08:58:40 +02:00
protected function _d3authenticate()
{
try {
2024-09-04 08:58:40 +02:00
$sUser = Registry::getRequest()->getRequestEscapedParameter('usr');
2020-11-11 22:29:10 +01:00
$sPassword = Registry::getRequest()->getRequestEscapedParameter('pwd');
2024-09-04 08:58:40 +02:00
if (!$sUser || !$sPassword) {
$sUser = $_SERVER[ 'PHP_AUTH_USER' ];
$sPassword = $_SERVER[ '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 ];
}
}
}
}
2018-02-23 12:30:57 +01:00
/** @var User $oUser */
$oUser = oxNew(User::class);
2024-09-04 08:58:40 +02:00
if (!$sUser || !$sPassword || !$oUser->login($sUser, $sPassword)) {
2018-02-23 12:30:57 +01:00
/** @var UserException $oEx */
$oEx = oxNew(UserException::class, 'EXCEPTION_USER_NOVALIDLOGIN');
throw $oEx;
}
2024-09-04 08:58:40 +02:00
} catch (Exception $oEx) {
$oShop = Registry::getConfig()->getActiveShop();
2024-09-04 08:58:40 +02:00
header('WWW-Authenticate: Basic realm="{' . $oShop->getFieldData('oxname') . '"');
header('HTTP/1.0 401 Unauthorized');
exit(1);
}
}
/**
2024-07-03 09:32:01 +02:00
* @return bool|d3_dev_oxorder|Order
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public function getOrder()
{
$oOrder = parent::getOrder();
if ((false == $oOrder || !$oOrder->getFieldData('oxordernr'))
2020-11-11 22:29:10 +01:00
&& $this->d3DevCanShowThankyou()
) {
2020-11-11 22:29:10 +01:00
try {
$this->_oOrder = $this->d3GetLastOrder();
$oOrder = $this->_oOrder;
if (!$oOrder || !$oOrder->getFieldData('oxordernr')) {
throw oxNew(\RuntimeException::class, 'unknown order');
}
} catch (Exception $e) {
die($e->getMessage());
}
}
return $oOrder;
}
/**
2024-07-03 09:32:01 +02:00
* @return d3_dev_oxorder
2018-02-23 12:30:57 +01:00
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
2024-07-03 09:32:01 +02:00
* @throws NoOrderFoundException
* @throws DBALDriverException
* @throws DBALException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
2024-07-03 09:32:01 +02:00
public function d3GetLastOrder(): d3_dev_oxorder
{
2018-02-23 12:30:57 +01:00
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
2024-07-03 09:32:01 +02:00
throw oxNew(UnauthorisedException::class);
}
/** @var d3_dev_oxorder $oOrder */
2018-02-23 12:30:57 +01:00
$oOrder = oxNew(Order::class);
$oOrder->d3getLastOrder();
return $oOrder;
}
}