cs fixer
This commit is contained in:
@@ -21,18 +21,18 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Admin\Controller;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
class AdminController extends BaseAdminController {
|
|
||||||
|
|
||||||
|
class AdminController extends BaseAdminController
|
||||||
|
{
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
return $this->render("home");
|
return $this->render("home");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processAction()
|
public function processAction()
|
||||||
{
|
{
|
||||||
echo "not yet coded !";
|
echo "not yet coded !";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,146 @@
|
|||||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Admin\Controller;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Controller\BaseController;
|
use Thelia\Controller\BaseController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||||
|
use Thelia\Tools\URL;
|
||||||
|
use Thelia\Tools\Redirect;
|
||||||
|
|
||||||
class BaseAdminController extends BaseController {
|
class BaseAdminController extends BaseController
|
||||||
|
{
|
||||||
|
const TEMPLATE_404 = "404";
|
||||||
|
|
||||||
}
|
public function processTemplateAction($template)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (! empty($template)) {
|
||||||
|
// If we have a view in the URL, render this view
|
||||||
|
return $this->render($template);
|
||||||
|
} elseif (null != $view = $this->getRequest()->get('view')) {
|
||||||
|
return $this->render($view);
|
||||||
|
}
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
// Nothing special
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->pageNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a 404 error
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected function pageNotFound()
|
||||||
|
{
|
||||||
|
return new Response($this->renderRaw(self::TEMPLATE_404), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a general error page
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected function errorPage($message)
|
||||||
|
{
|
||||||
|
return $this->render('general_error', array(
|
||||||
|
"error_message" => $message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check current admin user authorisations. An ADMIN role is assumed.
|
||||||
|
*
|
||||||
|
* @param unknown $permissions a single permission or an array of permissions.
|
||||||
|
*
|
||||||
|
* @throws AuthenticationException if permissions are not granted ti the current user.
|
||||||
|
*/
|
||||||
|
protected function checkAuth($permissions)
|
||||||
|
{
|
||||||
|
if (! $this->getSecurityContext()->isGranted(array("ADMIN"), is_array($permissions) ? $permissions : array($permissions))) {
|
||||||
|
throw new AuthorizationException("Sorry, you're not allowed to perform this action");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a ParserInterfac instance parser
|
||||||
|
*/
|
||||||
|
protected function getParser()
|
||||||
|
{
|
||||||
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
|
// Define the template thant shoud be used
|
||||||
|
$parser->setTemplate(ConfigQuery::read('base_admin_template', 'admin/default'));
|
||||||
|
|
||||||
|
return $parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forwards the request to another controller.
|
||||||
|
*
|
||||||
|
* @param string $controller The controller name (a string like BlogBundle:Post:index)
|
||||||
|
* @param array $path An array of path parameters
|
||||||
|
* @param array $query An array of query parameters
|
||||||
|
*
|
||||||
|
* @return Response A Response instance
|
||||||
|
*/
|
||||||
|
protected function forward($controller, array $path = array(), array $query = array())
|
||||||
|
{
|
||||||
|
$path['_controller'] = $controller;
|
||||||
|
$subRequest = $this->container->get('request')->duplicate($query, null, $path);
|
||||||
|
|
||||||
|
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the given template, and returns the result as an Http Response.
|
||||||
|
*
|
||||||
|
* @param $templateName the complete template name, with extension
|
||||||
|
* @param array $args the template arguments
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected function render($templateName, $args = array())
|
||||||
|
{
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
return $response->setContent($this->renderRaw($templateName, $args));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the given template, and returns the result as a string.
|
||||||
|
*
|
||||||
|
* @param $templateName the complete template name, with extension
|
||||||
|
* @param array $args the template arguments
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected function renderRaw($templateName, $args = array())
|
||||||
|
{
|
||||||
|
// Add the template standard extension
|
||||||
|
$templateName .= '.html';
|
||||||
|
|
||||||
|
$session = $this->getSession();
|
||||||
|
|
||||||
|
$args = array_merge($args, array(
|
||||||
|
'locale' => $session->getLocale(),
|
||||||
|
'lang' => $session->getLang()
|
||||||
|
));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$data = $this->getParser()->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::absoluteUrl($ex->getLoginTemplate()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,119 +21,130 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Admin\Controller;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
use Thelia\Model\CategoryQuery;
|
|
||||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||||
|
|
||||||
class CategoryController extends BaseAdminController {
|
class CategoryController extends BaseAdminController
|
||||||
|
{
|
||||||
|
protected function createNewCategory($args)
|
||||||
|
{
|
||||||
|
$this->dispatchEvent("createCategory");
|
||||||
|
|
||||||
protected function createNewCategory($args) {
|
// At this point, the form has error, and should be redisplayed.
|
||||||
$this->dispatchEvent("createCategory");
|
return $this->render('categories', $args);
|
||||||
|
}
|
||||||
|
|
||||||
// At this point, the form has error, and should be redisplayed.
|
protected function editCategory($args)
|
||||||
return $this->render('categories', $args);
|
{
|
||||||
}
|
$this->checkAuth("ADMIN", "admin.category.edit");
|
||||||
|
|
||||||
protected function editCategory($args) {
|
return $this->render('edit_category', $args);
|
||||||
|
}
|
||||||
|
|
||||||
$this->checkAuth("ADMIN", "admin.category.edit");
|
protected function deleteCategory($args)
|
||||||
|
{
|
||||||
|
$this->dispatchEvent("deleteCategory");
|
||||||
|
|
||||||
return $this->render('edit_category', $args);
|
// Something was wrong, category was not deleted. Display parent category list
|
||||||
}
|
return $this->render('categories', $args);
|
||||||
|
}
|
||||||
|
|
||||||
protected function deleteCategory($args) {
|
protected function browseCategory($args)
|
||||||
$this->dispatchEvent("deleteCategory");
|
{
|
||||||
|
$this->checkAuth("AMIN", "admin.catalog.view");
|
||||||
|
|
||||||
// Something was wrong, category was not deleted. Display parent category list
|
return $this->render('categories', $args);
|
||||||
return $this->render('categories', $args);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected function browseCategory($args) {
|
protected function visibilityToggle($args)
|
||||||
|
{
|
||||||
|
$this->dispatchEvent("toggleCategoryVisibility");
|
||||||
|
|
||||||
$this->checkAuth("AMIN", "admin.catalog.view");
|
return $this->nullResponse();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('categories', $args);
|
protected function changePosition($args)
|
||||||
}
|
{
|
||||||
|
$this->dispatchEvent("changeCategoryPosition");
|
||||||
|
|
||||||
protected function visibilityToggle($args) {
|
return $this->render('categories', $args);
|
||||||
$this->dispatchEvent("toggleCategoryVisibility");
|
}
|
||||||
|
|
||||||
return $this->nullResponse();
|
protected function positionDown($args)
|
||||||
}
|
{
|
||||||
|
$this->dispatchEvent("changeCategoryPositionDown");
|
||||||
|
|
||||||
protected function changePosition($args) {
|
return $this->render('categories', $args);
|
||||||
$this->dispatchEvent("changeCategoryPosition");
|
}
|
||||||
|
|
||||||
return $this->render('categories', $args);
|
protected function positionUp($args)
|
||||||
}
|
{
|
||||||
|
$this->dispatchEvent("changeCategoryPositionUp");
|
||||||
|
|
||||||
protected function positionDown($args) {
|
return $this->render('categories', $args);
|
||||||
$this->dispatchEvent("changeCategoryPositionDown");
|
}
|
||||||
|
|
||||||
return $this->render('categories', $args);
|
public function indexAction()
|
||||||
}
|
{
|
||||||
|
return $this->processAction();
|
||||||
protected function positionUp($args) {
|
}
|
||||||
$this->dispatchEvent("changeCategoryPositionUp");
|
|
||||||
|
|
||||||
return $this->render('categories', $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function indexAction()
|
|
||||||
{
|
|
||||||
return $this->processAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processAction()
|
public function processAction()
|
||||||
{
|
{
|
||||||
// Get the current action
|
// Get the current action
|
||||||
$action = $this->getRequest()->get('action', 'browse');
|
$action = $this->getRequest()->get('action', 'browse');
|
||||||
|
|
||||||
// Get the category ID
|
// Get the category ID
|
||||||
$id = $this->getRequest()->get('id', 0);
|
$id = $this->getRequest()->get('id', 0);
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'action' => $action,
|
'action' => $action,
|
||||||
'current_category_id' => $id
|
'current_category_id' => $id
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch($action) {
|
switch ($action) {
|
||||||
case 'browse' : // Browse categories
|
case 'browse' : // Browse categories
|
||||||
return $this->browseCategory($args);
|
|
||||||
|
|
||||||
case 'create' : // Create a new category
|
return $this->browseCategory($args);
|
||||||
return $this->createNewCategory($args);
|
|
||||||
|
|
||||||
case 'edit' : // Edit an existing category
|
case 'create' : // Create a new category
|
||||||
return $this->editCategory($args);
|
|
||||||
|
|
||||||
case 'delete' : // Delete an existing category
|
return $this->createNewCategory($args);
|
||||||
return $this->deleteCategory($args);
|
|
||||||
|
|
||||||
case 'visibilityToggle' : // Toggle visibility
|
case 'edit' : // Edit an existing category
|
||||||
return $this->visibilityToggle($id);
|
|
||||||
|
|
||||||
case 'changePosition' : // Change position
|
return $this->editCategory($args);
|
||||||
return $this->changePosition($args);
|
|
||||||
|
|
||||||
case 'positionUp' : // Move up category
|
case 'delete' : // Delete an existing category
|
||||||
return $this->positionUp($args);
|
|
||||||
|
|
||||||
case 'positionDown' : // Move down category
|
return $this->deleteCategory($args);
|
||||||
return $this->positionDown($args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(AuthorizationException $ex) {
|
|
||||||
return $this->errorPage($ex->getMessage());
|
|
||||||
}
|
|
||||||
catch(AuthenticationException $ex) {
|
|
||||||
return $this->errorPage($ex->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// We did not recognized the action -> return a 404 page
|
case 'visibilityToggle' : // Toggle visibility
|
||||||
return $this->pageNotFound();
|
|
||||||
|
return $this->visibilityToggle($id);
|
||||||
|
|
||||||
|
case 'changePosition' : // Change position
|
||||||
|
|
||||||
|
return $this->changePosition($args);
|
||||||
|
|
||||||
|
case 'positionUp' : // Move up category
|
||||||
|
|
||||||
|
return $this->positionUp($args);
|
||||||
|
|
||||||
|
case 'positionDown' : // Move down category
|
||||||
|
|
||||||
|
return $this->positionDown($args);
|
||||||
|
}
|
||||||
|
} catch (AuthorizationException $ex) {
|
||||||
|
return $this->errorPage($ex->getMessage());
|
||||||
|
} catch (AuthenticationException $ex) {
|
||||||
|
return $this->errorPage($ex->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// We did not recognized the action -> return a 404 page
|
||||||
|
return $this->pageNotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Admin\Controller;
|
namespace Thelia\Controller\Admin;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Thelia\Form\AdminLogin;
|
use Thelia\Form\AdminLogin;
|
||||||
use Thelia\Core\Security\Authentication\AdminUsernamePasswordFormAuthenticator;
|
use Thelia\Core\Security\Authentication\AdminUsernamePasswordFormAuthenticator;
|
||||||
use Thelia\Model\AdminLog;
|
use Thelia\Model\AdminLog;
|
||||||
@@ -33,73 +32,70 @@ use Thelia\Tools\URL;
|
|||||||
use Thelia\Tools\Redirect;
|
use Thelia\Tools\Redirect;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
|
||||||
class SessionController extends BaseAdminController {
|
class SessionController extends BaseAdminController
|
||||||
|
{
|
||||||
|
public function showLoginAction()
|
||||||
|
{
|
||||||
|
return $this->render("login");
|
||||||
|
}
|
||||||
|
|
||||||
public function showLoginAction()
|
public function checkLogoutAction()
|
||||||
{
|
{
|
||||||
return $this->render("login");
|
$this->dispatch(TheliaEvents::ADMIN_LOGOUT);
|
||||||
}
|
|
||||||
|
|
||||||
public function checkLogoutAction()
|
$this->getSecurityContext()->clear();
|
||||||
{
|
|
||||||
$this->dispatch(TheliaEvents::ADMIN_LOGOUT);
|
|
||||||
|
|
||||||
$this->getSecurityContext()->clear();
|
// Go back to login page.
|
||||||
|
return Redirect::exec(URL::absoluteUrl('/admin/login')); // FIXME - should be a parameter
|
||||||
// Go back to login page.
|
}
|
||||||
return Redirect::exec(URL::absoluteUrl('/admin/login')); // FIXME - should be a parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkLoginAction()
|
public function checkLoginAction()
|
||||||
{
|
{
|
||||||
$adminLoginForm = new AdminLogin($this->getRequest());
|
$adminLoginForm = new AdminLogin($this->getRequest());
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm);
|
$authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = $authenticator->getAuthentifiedUser();
|
$user = $authenticator->getAuthentifiedUser();
|
||||||
|
|
||||||
// Success -> store user in security context
|
// Success -> store user in security context
|
||||||
$this->getSecurityContext()->setUser($user);
|
$this->getSecurityContext()->setUser($user);
|
||||||
|
|
||||||
// Log authentication success
|
// Log authentication success
|
||||||
AdminLog::append("Authentication successful", $request, $user);
|
AdminLog::append("Authentication successful", $request, $user);
|
||||||
|
|
||||||
$this->dispatch(TheliaEvents::ADMIN_LOGIN);
|
$this->dispatch(TheliaEvents::ADMIN_LOGIN);
|
||||||
|
|
||||||
// Redirect to the success URL
|
// Redirect to the success URL
|
||||||
return Redirect::exec($adminLoginForm->getSuccessUrl());
|
return Redirect::exec($adminLoginForm->getSuccessUrl());
|
||||||
}
|
} catch (ValidatorException $ex) {
|
||||||
catch (ValidatorException $ex) {
|
|
||||||
|
|
||||||
// Validation problem
|
// Validation problem
|
||||||
$message = "Missing or invalid information. Please check your input.";
|
$message = "Missing or invalid information. Please check your input.";
|
||||||
}
|
} catch (AuthenticationException $ex) {
|
||||||
catch (AuthenticationException $ex) {
|
|
||||||
|
|
||||||
// Log authentication failure
|
// Log authentication failure
|
||||||
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
|
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
|
||||||
|
|
||||||
$message = "Login failed. Please check your username and password.";
|
$message = "Login failed. Please check your username and password.";
|
||||||
}
|
} catch (\Exception $ex) {
|
||||||
catch (\Exception $ex) {
|
|
||||||
|
|
||||||
// Log authentication failure
|
// Log authentication failure
|
||||||
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);
|
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);
|
||||||
|
|
||||||
$message = "Unable to process your request. Please try again.";
|
$message = "Unable to process your request. Please try again.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store error information in the form
|
// Store error information in the form
|
||||||
$adminLoginForm->setError(true);
|
$adminLoginForm->setError(true);
|
||||||
$adminLoginForm->setErrorMessage($message);
|
$adminLoginForm->setErrorMessage($message);
|
||||||
|
|
||||||
// Store the form name in session (see Form Smarty plugin to find usage of this parameter)
|
// Store the form name in session (see Form Smarty plugin to find usage of this parameter)
|
||||||
$this->getParserContext()->setErrorForm($adminLoginForm);
|
$this->getParserContext()->setErrorForm($adminLoginForm);
|
||||||
|
|
||||||
// Display the login form again
|
// Display the login form again
|
||||||
return $this->render("login");
|
return $this->render("login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,9 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Controller;
|
namespace Thelia\Controller;
|
||||||
|
|
||||||
use Symfony\Component\Routing\RequestContext;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||||
|
|
||||||
use Thelia\Form\BaseForm;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
||||||
use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
|
|
||||||
use Thelia\Model\ConfigQuery;
|
|
||||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
|
||||||
use Thelia\Core\Security\SecurityContext;
|
use Thelia\Core\Security\SecurityContext;
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
use Thelia\Tools\Redirect;
|
use Thelia\Tools\Redirect;
|
||||||
@@ -40,7 +32,6 @@ use Thelia\Core\Template\ParserContext;
|
|||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
use Thelia\Core\Factory\ActionEventFactory;
|
use Thelia\Core\Factory\ActionEventFactory;
|
||||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -53,113 +44,13 @@ use Thelia\Core\Security\Exception\AuthorizationException;
|
|||||||
|
|
||||||
class BaseController extends ContainerAware
|
class BaseController extends ContainerAware
|
||||||
{
|
{
|
||||||
const TEMPLATE_404 = "404";
|
|
||||||
|
|
||||||
public function processTemplateAction($template)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (! empty($template)) {
|
|
||||||
// If we have a view in the URL, render this view
|
|
||||||
return $this->render($template);
|
|
||||||
}
|
|
||||||
else if (null != $view = $this->getRequest()->get('view')) {
|
|
||||||
return $this->render($view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\Exception $ex) {
|
|
||||||
// Nothing special
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->pageNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a 404 error
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
|
||||||
protected function pageNotFound() {
|
|
||||||
return new Response($this->renderRaw(self::TEMPLATE_404), 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a general error page
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
|
||||||
protected function errorPage($message) {
|
|
||||||
return $this->render('general_error', array(
|
|
||||||
"error_message" => $message)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check current admin user authorisations. An ADMIN role is assumed.
|
|
||||||
*
|
|
||||||
* @param unknown $permissions a single permission or an array of permissions.
|
|
||||||
*
|
|
||||||
* @throws AuthenticationException if permissions are not granted ti the current user.
|
|
||||||
*/
|
|
||||||
protected function checkAuth($permissions) {
|
|
||||||
|
|
||||||
if (! $this->getSecurityContext()->isGranted(array("ADMIN"), is_array($permissions) ? $permissions : array($permissions))) {
|
|
||||||
throw new AuthorizationException("Sorry, you're not allowed to perform this action");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an empty response (after an ajax request, for example)
|
|
||||||
*/
|
|
||||||
protected function nullResponse()
|
|
||||||
{
|
|
||||||
return new Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the given template, and returns the result as an Http Response.
|
* Return an empty response (after an ajax request, for example)
|
||||||
*
|
|
||||||
* @param $templateName the complete template name, with extension
|
|
||||||
* @param array $args the template arguments
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
*/
|
||||||
protected function render($templateName, $args = array())
|
protected function nullResponse()
|
||||||
{
|
{
|
||||||
$response = new Response();
|
return new Response();
|
||||||
|
|
||||||
return $response->setContent($this->renderRaw($templateName, $args));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the given template, and returns the result as a string.
|
|
||||||
*
|
|
||||||
* @param $templateName the complete template name, with extension
|
|
||||||
* @param array $args the template arguments
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
|
||||||
protected function renderRaw($templateName, $args = array())
|
|
||||||
{
|
|
||||||
// Add the template standard extension
|
|
||||||
$templateName .= '.html';
|
|
||||||
|
|
||||||
$session = $this->getSession();
|
|
||||||
|
|
||||||
$args = array_merge($args, array(
|
|
||||||
'locale' => $session->getLocale(),
|
|
||||||
'lang' => $session->getLang()
|
|
||||||
));
|
|
||||||
|
|
||||||
try {
|
|
||||||
$data = $this->getParser()->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::absoluteUrl($ex->getLoginTemplate()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,29 +60,29 @@ class BaseController extends ContainerAware
|
|||||||
*/
|
*/
|
||||||
protected function dispatchEvent($action)
|
protected function dispatchEvent($action)
|
||||||
{
|
{
|
||||||
// Create the
|
// Create the
|
||||||
$eventFactory = new ActionEventFactory($this->getRequest(), $action, $this->container->getParameter("thelia.actionEvent"));
|
$eventFactory = new ActionEventFactory($this->getRequest(), $action, $this->container->getParameter("thelia.actionEvent"));
|
||||||
|
|
||||||
$actionEvent = $eventFactory->createActionEvent();
|
$actionEvent = $eventFactory->createActionEvent();
|
||||||
|
|
||||||
$this->dispatch("action.$action", $actionEvent);
|
$this->dispatch("action.$action", $actionEvent);
|
||||||
|
|
||||||
if ($actionEvent->hasErrorForm()) {
|
if ($actionEvent->hasErrorForm()) {
|
||||||
$this->getParserContext()->setErrorForm($actionEvent->getErrorForm());
|
$this->getParserContext()->setErrorForm($actionEvent->getErrorForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $actionEvent;
|
return $actionEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a Thelia event to modules
|
* Dispatch a Thelia event to modules
|
||||||
*
|
*
|
||||||
* @param string $eventName a TheliaEvent name, as defined in TheliaEvents class
|
* @param string $eventName a TheliaEvent name, as defined in TheliaEvents class
|
||||||
* @param ActionEvent $event the event
|
* @param ActionEvent $event the event
|
||||||
*/
|
*/
|
||||||
protected function dispatch($eventName, ActionEvent $event = null) {
|
protected function dispatch($eventName, ActionEvent $event = null)
|
||||||
|
{
|
||||||
$this->getDispatcher()->dispatch($eventName, $event);
|
$this->getDispatcher()->dispatch($eventName, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +92,7 @@ class BaseController extends ContainerAware
|
|||||||
*/
|
*/
|
||||||
public function getDispatcher()
|
public function getDispatcher()
|
||||||
{
|
{
|
||||||
return $this->container->get('event_dispatcher');
|
return $this->container->get('event_dispatcher');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,21 +102,21 @@ class BaseController extends ContainerAware
|
|||||||
*/
|
*/
|
||||||
protected function getParserContext()
|
protected function getParserContext()
|
||||||
{
|
{
|
||||||
return $this->container->get('thelia.parser.context');
|
return $this->container->get('thelia.parser.context');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the security context, by default in admin mode.
|
* Return the security context, by default in admin mode.
|
||||||
*
|
*
|
||||||
* @return Thelia\Core\Security\SecurityContext
|
* @return \Thelia\Core\Security\SecurityContext
|
||||||
*/
|
*/
|
||||||
protected function getSecurityContext($context = false)
|
protected function getSecurityContext($context = false)
|
||||||
{
|
{
|
||||||
$securityContext = $this->container->get('thelia.securityContext');
|
$securityContext = $this->container->get('thelia.securityContext');
|
||||||
|
|
||||||
$securityContext->setContext($context === false ? SecurityContext::CONTEXT_BACK_OFFICE : $context);
|
$securityContext->setContext($context === false ? SecurityContext::CONTEXT_BACK_OFFICE : $context);
|
||||||
|
|
||||||
return $securityContext;
|
return $securityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,40 +132,30 @@ class BaseController extends ContainerAware
|
|||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
|
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||||
*/
|
*/
|
||||||
protected function getSession() {
|
protected function getSession()
|
||||||
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$request = $this->getRequest();
|
return $request->getSession();
|
||||||
|
|
||||||
return $request->getSession();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a ParserInterfac instance parser
|
*
|
||||||
|
* redirect request to specify url
|
||||||
|
* @param string $url
|
||||||
*/
|
*/
|
||||||
protected function getParser()
|
public function redirect($url)
|
||||||
{
|
{
|
||||||
$parser = $this->container->get("thelia.parser");
|
Redirect::exec($url);
|
||||||
|
|
||||||
// Define the template thant shoud be used
|
|
||||||
$parser->setTemplate(ConfigQuery::read('base_admin_template', 'admin/default'));
|
|
||||||
|
|
||||||
return $parser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards the request to another controller.
|
* If success_url param is present in request, follow this link.
|
||||||
*
|
|
||||||
* @param string $controller The controller name (a string like BlogBundle:Post:index)
|
|
||||||
* @param array $path An array of path parameters
|
|
||||||
* @param array $query An array of query parameters
|
|
||||||
*
|
|
||||||
* @return Response A Response instance
|
|
||||||
*/
|
*/
|
||||||
protected function forward($controller, array $path = array(), array $query = array())
|
protected function redirectSuccess()
|
||||||
{
|
{
|
||||||
$path['_controller'] = $controller;
|
if (null !== $url = $this->getRequest()->get("success_url")) {
|
||||||
$subRequest = $this->container->get('request')->duplicate($query, null, $path);
|
$this->redirect($url);
|
||||||
|
}
|
||||||
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class DefaultController implements NullControllerInterface
|
|||||||
$view = $request->request->get('view');
|
$view = $request->request->get('view');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$request->attributes->set('_view', $view);
|
$request->attributes->set('_view', $view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Controller\Front;
|
namespace Thelia\Controller\Front;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Controller\BaseController;
|
use Thelia\Controller\BaseController;
|
||||||
use Thelia\Tools\Redirect;
|
|
||||||
|
|
||||||
class BaseFrontController extends BaseController {
|
class BaseFrontController extends BaseController
|
||||||
|
{
|
||||||
public function redirect($url) {
|
}
|
||||||
Redirect::exec($url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Controller\Front;
|
namespace Thelia\Controller\Front;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Core\Event\CartEvent;
|
use Thelia\Core\Event\CartEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
|
||||||
@@ -65,10 +64,4 @@ class CartController extends BaseFrontController
|
|||||||
return new CartEvent($request, $cart);
|
return new CartEvent($request, $cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function redirectInternal()
|
}
|
||||||
{
|
|
||||||
if (null !== $url = $this->getRequest()->get("success_url")) {
|
|
||||||
$this->redirect($url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,20 +22,18 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Controller\Front;
|
namespace Thelia\Controller\Front;
|
||||||
|
|
||||||
use Thelia\Controller\BaseController;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
|
||||||
use Thelia\Core\Event\CustomerEvent;
|
use Thelia\Core\Event\CustomerEvent;
|
||||||
use Thelia\Core\Security\SecurityContext;
|
use Thelia\Core\Security\SecurityContext;
|
||||||
use Thelia\Model\Customer;
|
use Thelia\Model\Customer;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
|
|
||||||
class CustomerController extends BaseFrontController {
|
class CustomerController extends BaseFrontController
|
||||||
|
{
|
||||||
public function createAction()
|
public function createAction()
|
||||||
{
|
{
|
||||||
|
|
||||||
$event = $this->dispatchEvent("createCustomer");
|
$event = $this->dispatchEvent("createCustomer");
|
||||||
if(null !== $customer = $event->customer) {
|
if (null !== $customer = $event->customer) {
|
||||||
$this->processLogin($event->customer);
|
$this->processLogin($event->customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,4 +60,4 @@ class CustomerController extends BaseFrontController {
|
|||||||
if($sendLogin) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
|
if($sendLogin) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user