no-return-functions block
This commit is contained in:
@@ -203,6 +203,7 @@
|
||||
|
||||
<service id="smarty.plugin.security" class="Thelia\Core\Template\Smarty\Plugins\Security" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="thelia.securityContext" />
|
||||
</service>
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ class BaseFrontController extends BaseController
|
||||
|
||||
protected function checkCartNotEmpty()
|
||||
{
|
||||
if($this->getSession()->getCart()->countCartItems() == 0) {
|
||||
$cart = $this->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
$this->redirectToRoute("cart.view");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\OrderDelivery;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\Base\AddressQuery;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||
use Thelia\Model\Order;
|
||||
|
||||
/**
|
||||
@@ -53,9 +54,6 @@ class OrderController extends BaseFrontController
|
||||
|
||||
$orderDelivery = new OrderDelivery($this->getRequest());
|
||||
|
||||
$x = $this->getRequest();
|
||||
$y = $_POST;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($orderDelivery, "post");
|
||||
|
||||
@@ -69,7 +67,12 @@ class OrderController extends BaseFrontController
|
||||
}
|
||||
|
||||
/* check that the delivery module fetch the delivery address area */
|
||||
|
||||
if(AreaDeliveryModuleQuery::create()
|
||||
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
||||
->filterByDeliveryModuleId()
|
||||
->count() == 0) {
|
||||
throw new \Exception("PUKE");
|
||||
}
|
||||
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
|
||||
@@ -23,18 +23,22 @@
|
||||
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Exception\OrderException;
|
||||
|
||||
class Security extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $request;
|
||||
private $securityContext;
|
||||
|
||||
public function __construct(SecurityContext $securityContext)
|
||||
public function __construct(Request $request, SecurityContext $securityContext)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,32 +47,43 @@ class Security extends AbstractSmartyPlugin
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string no text is returned.
|
||||
* @throws \Thelia\Core\Security\Exception\AuthenticationException
|
||||
*/
|
||||
public function checkAuthFunction($params, &$smarty)
|
||||
{
|
||||
$roles = $this->_explode($this->getParam($params, 'roles'));
|
||||
$permissions = $this->_explode($this->getParam($params, 'permissions'));
|
||||
$roles = $this->_explode($this->getParam($params, 'roles'));
|
||||
$permissions = $this->_explode($this->getParam($params, 'permissions'));
|
||||
|
||||
if (! $this->securityContext->isGranted($roles, $permissions)) {
|
||||
if (! $this->securityContext->isGranted($roles, $permissions)) {
|
||||
|
||||
$ex = new AuthenticationException(
|
||||
sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
|
||||
implode(',', $roles), implode(',', $permissions), $context
|
||||
)
|
||||
);
|
||||
$ex = new AuthenticationException(
|
||||
sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
|
||||
implode(',', $roles), implode(',', $permissions), $context
|
||||
)
|
||||
);
|
||||
|
||||
$loginTpl = $this->getParam($params, 'login_tpl');
|
||||
$loginTpl = $this->getParam($params, 'login_tpl');
|
||||
|
||||
if (null != $loginTpl) {
|
||||
$ex->setLoginTemplate($loginTpl);
|
||||
}
|
||||
if (null != $loginTpl) {
|
||||
$ex->setLoginTemplate($loginTpl);
|
||||
}
|
||||
|
||||
throw $ex;
|
||||
}
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return '';
|
||||
return '';
|
||||
}
|
||||
|
||||
public function checkCartNotEmptyFunction($params, &$smarty)
|
||||
{
|
||||
$cart = $this->request->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
throw new OrderException('Cart must not be empty', OrderException::CART_EMPTY);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the various smarty plugins handled by this class
|
||||
*
|
||||
@@ -77,7 +92,8 @@ class Security extends AbstractSmartyPlugin
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction')
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction'),
|
||||
new SmartyPluginDescriptor('function', 'check_cart_not_empty', $this, 'checkCartNotEmptyFunction'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
39
core/lib/Thelia/Exception/OrderException.php
Executable file
39
core/lib/Thelia/Exception/OrderException.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Exception;
|
||||
|
||||
class OrderException extends \RuntimeException
|
||||
{
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
const CART_EMPTY = 100;
|
||||
|
||||
public function __construct($message, $code = null, $previous = null)
|
||||
{
|
||||
if ($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user