diff --git a/core/lib/Thelia/Action/PageNotFound.php b/core/lib/Thelia/Action/HttpException.php similarity index 77% rename from core/lib/Thelia/Action/PageNotFound.php rename to core/lib/Thelia/Action/HttpException.php index c6593ff7c..9cb9fab13 100755 --- a/core/lib/Thelia/Action/PageNotFound.php +++ b/core/lib/Thelia/Action/HttpException.php @@ -32,29 +32,38 @@ use Thelia\Model\ConfigQuery; /** * - * Class PageNotFound + * Class HttpException * @package Thelia\Action * @author Etienne Roudeix */ -class PageNotFound extends BaseAction implements EventSubscriberInterface +class HttpException extends BaseAction implements EventSubscriberInterface { - public function display404(GetResponseForExceptionEvent $event) + public function checkHttpException(GetResponseForExceptionEvent $event) { if ($event->getException() instanceof NotFoundHttpException) { - - $parser = $this->container->get("thelia.parser"); - - // Define the template thant shoud be used - $parser->setTemplate(ConfigQuery::getActiveTemplate()); - - //$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView()); - - $response = new Response($parser->render(ConfigQuery::getPageNotFoundView()), 404); - - $event->setResponse($response); + $this->display404($event); } } + protected function display404(GetResponseForExceptionEvent $event) + { + $parser = $this->container->get("thelia.parser"); + + // Define the template thant shoud be used + $parser->setTemplate(ConfigQuery::getActiveTemplate()); + + //$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView()); + + $response = new Response($parser->render(ConfigQuery::getPageNotFoundView()), 404); + + $event->setResponse($response); + } + + protected function display403(GetResponseForExceptionEvent $event) + { + $event->setResponse(new Response("You don't have access to this resources", 403)); + } + /** * Returns an array of event names this subscriber wants to listen to. * @@ -78,7 +87,7 @@ class PageNotFound extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - KernelEvents::EXCEPTION => array("display404", 128), + KernelEvents::EXCEPTION => array("checkHttpException", 128), ); } } diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 842acdc6f..2b86ed33e 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -67,7 +67,7 @@ - + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 49713b938..c50fd97b9 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -66,12 +66,19 @@ Thelia\Controller\Front\DefaultController::noAction - address_edit + address-edit Thelia\Controller\Front\AddressController::updateAction + + + Thelia\Controller\Front\AddressController::generateModalAction + modal-address + \d+ + + @@ -94,6 +101,8 @@ cart + + Thelia\Controller\Front\DeliveryController::select diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 988159be4..ee23eb8a2 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -25,6 +25,7 @@ namespace Thelia\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Exception\InvalidParameterException; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -263,4 +264,16 @@ class BaseController extends ContainerAware { return $this->container->getParameter('kernel.debug'); } + + /** + * check if the current http request is a XmlHttpRequest. + * + * If not, send a + */ + protected function checkXmlHttpRequest() + { + if(false === $this->getRequest()->isXmlHttpRequest() && false === $this->isDebug()) { + throw new AccessDeniedHttpException(); + } + } } diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 92d54695c..91f7d1a41 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -39,6 +39,15 @@ use Thelia\Tools\URL; class AddressController extends BaseFrontController { + /** + * Controller for generate modal containing update form + * Check if request is a XmlHttpRequest and address owner is the current customer + * @param $address_id + */ + public function generateModalAction($address_id) + { + $this->checkXmlHttpRequest(); + } /** * Create controller. * Check if customer is logged in diff --git a/templates/default/modal-address.html b/templates/default/modal-address.html new file mode 100644 index 000000000..e69de29bb