return redirectReponse insteadof sending it
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
@@ -402,7 +403,15 @@ class BaseAdminController extends BaseController
|
||||
*/
|
||||
protected function render($templateName, $args = array(), $status = 200)
|
||||
{
|
||||
return Response::create($this->renderRaw($templateName, $args), $status);
|
||||
try {
|
||||
$response = Response::create($this->renderRaw($templateName, $args), $status);
|
||||
} catch (AuthenticationException $ex) {
|
||||
// User is not authenticated, and templates requires authentication -> redirect to login page
|
||||
// We user login_tpl as a path, not a template.
|
||||
$response = RedirectResponse::create(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,10 +462,6 @@ class BaseAdminController extends BaseController
|
||||
$data = $this->getParser($templateDir)->render($templateName, $args);
|
||||
|
||||
return $data;
|
||||
} catch (AuthenticationException $ex) {
|
||||
// User is not authenticated, and templates requires authentication -> redirect to login page
|
||||
// We user login_tpl as a path, not a template.
|
||||
Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
|
||||
} catch (AuthorizationException $ex) {
|
||||
// User is not allowed to perform the required action. Return the error page instead of the requested page.
|
||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."), 403);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace Thelia\Core\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||
@@ -68,7 +69,7 @@ class ViewListener implements EventSubscriberInterface
|
||||
$parser = $this->container->get('thelia.parser');
|
||||
$parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||
$request = $this->container->get('request');
|
||||
|
||||
$response = null;
|
||||
try {
|
||||
$content = $parser->render($request->attributes->get('_view').".html");
|
||||
|
||||
@@ -78,29 +79,31 @@ class ViewListener implements EventSubscriberInterface
|
||||
$response = new Response($content, $parser->getStatus() ?: 200);
|
||||
}
|
||||
|
||||
$event->setResponse($response);
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
throw new NotFoundHttpException();
|
||||
} catch (AuthenticationException $ex) {
|
||||
|
||||
// Redirect to the login template
|
||||
Redirect::exec($this->container->get('thelia.url.manager')->viewUrl($ex->getLoginTemplate()));
|
||||
$response = RedirectResponse::create($this->container->get('thelia.url.manager')->viewUrl($ex->getLoginTemplate()));
|
||||
} catch (OrderException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case OrderException::CART_EMPTY:
|
||||
// Redirect to the cart template
|
||||
Redirect::exec($this->container->get('router.chainRequest')->generate($e->cartRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
$response = RedirectResponse::create($this->container->get('router.chainRequest')->generate($e->cartRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
break;
|
||||
case OrderException::UNDEFINED_DELIVERY:
|
||||
// Redirect to the delivery choice template
|
||||
Redirect::exec($this->container->get('router.chainRequest')->generate($e->orderDeliveryRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
$response = RedirectResponse::create($this->container->get('router.chainRequest')->generate($e->orderDeliveryRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
break;
|
||||
}
|
||||
|
||||
if (null === $response) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$event->setResponse($response);
|
||||
}
|
||||
|
||||
public function beforeKernelView(GetResponseForControllerResultEvent $event)
|
||||
{
|
||||
$request = $this->container->get('request');
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Front\Controller;
|
||||
|
||||
use Front\Front;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Controller\Front\BaseFrontController;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerLoginEvent;
|
||||
@@ -308,7 +309,9 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
$this->processLogin($customer);
|
||||
|
||||
$this->redirectSuccess($customerLoginForm);
|
||||
$successUrl = $customerLoginForm->getSuccessUrl();
|
||||
|
||||
return RedirectResponse::create($successUrl);
|
||||
|
||||
} catch (UsernameNotFoundException $e) {
|
||||
$message = "Wrong email or password. Please try again";
|
||||
@@ -346,7 +349,7 @@ class CustomerController extends BaseFrontController
|
||||
}
|
||||
|
||||
// Redirect to home page
|
||||
$this->redirect(URL::getInstance()->getIndexPage());
|
||||
return RedirectResponse::create(URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user