return redirectReponse insteadof sending it

This commit is contained in:
Manuel Raynaud
2014-04-28 20:45:58 +02:00
parent c4b2898830
commit 8aa5912a7a
3 changed files with 25 additions and 14 deletions

View File

@@ -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);