Fixed customer front controller, events, addec admion config.
This commit is contained in:
@@ -52,11 +52,13 @@ class BaseAdminController extends BaseController
|
||||
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')) {
|
||||
}
|
||||
elseif (null != $view = $this->getRequest()->get('view')) {
|
||||
return $this->render($view);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
// Nothing special
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
return new Response($this->errorPage($ex->getMessage()));
|
||||
}
|
||||
|
||||
return $this->pageNotFound();
|
||||
|
||||
@@ -33,6 +33,7 @@ use Thelia\Core\Event\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryChangePositionEvent;
|
||||
use Thelia\Form\CategoryDeletionForm;
|
||||
use Thelia\Model\Lang;
|
||||
|
||||
class CategoryController extends BaseAdminController
|
||||
{
|
||||
@@ -99,7 +100,7 @@ class CategoryController extends BaseAdminController
|
||||
$this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId()));
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $categoryDeleteEvent->getDeletedCategory()->getId(), $categoryDeletionForm->getSuccessUrl());
|
||||
$successUrl = str_replace('_ID_', $categoryDeleteEvent->getDeletedCategory()->getParent(), $categoryDeletionForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
@@ -185,11 +186,34 @@ class CategoryController extends BaseAdminController
|
||||
// Get the category ID
|
||||
$id = $this->getRequest()->get('id', 0);
|
||||
|
||||
// Find the current order
|
||||
$category_order = $this->getRequest()->get(
|
||||
'category_order',
|
||||
$this->getSession()->get('admin.category_order', 'manual')
|
||||
);
|
||||
|
||||
// Find the current edit language ID
|
||||
$edition_language = $this->getRequest()->get(
|
||||
'edition_language',
|
||||
$this->getSession()->get('admin.edition_language', Lang::getDefaultLanguage()->getId())
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'action' => $action,
|
||||
'current_category_id' => $id
|
||||
'current_category_id' => $id,
|
||||
'category_order' => $category_order,
|
||||
'edition_language' => $edition_language,
|
||||
'date_format' => Lang::getDefaultLanguage()->getDateFormat(),
|
||||
'time_format' => Lang::getDefaultLanguage()->getTimeFormat(),
|
||||
'datetime_format' => Lang::getDefaultLanguage()->getDateTimeFormat(),
|
||||
);
|
||||
|
||||
// Store the current sort order in session
|
||||
$this->getSession()->set('admin.category_order', $category_order);
|
||||
|
||||
// Store the current edition language in session
|
||||
$this->getSession()->set('admin.edition_language', $edition_language);
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
case 'browse' : // Browse categories
|
||||
|
||||
@@ -51,13 +51,16 @@ class SessionController extends BaseAdminController
|
||||
|
||||
public function checkLoginAction()
|
||||
{
|
||||
$adminLoginForm = new AdminLogin($this->getRequest());
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm);
|
||||
$adminLoginForm = new AdminLogin($request);
|
||||
|
||||
try {
|
||||
|
||||
$form = $this->validateForm($adminLoginForm, "post");
|
||||
|
||||
$authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm);
|
||||
|
||||
$user = $authenticator->getAuthentifiedUser();
|
||||
|
||||
// Success -> store user in security context
|
||||
@@ -85,7 +88,7 @@ class SessionController extends BaseAdminController
|
||||
// Log authentication failure
|
||||
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.".$ex->getMessage();
|
||||
}
|
||||
|
||||
// Store error information in the form
|
||||
|
||||
@@ -35,6 +35,7 @@ use Thelia\Core\Factory\ActionEventFactory;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Core\Event\DefaultActionEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -60,10 +61,12 @@ class BaseController extends ContainerAware
|
||||
* Dispatch a Thelia event
|
||||
*
|
||||
* @param string $eventName a TheliaEvent name, as defined in TheliaEvents class
|
||||
* @param Event $event the event
|
||||
* @param Event $event the action event, or null (a DefaultActionEvent will be dispatched)
|
||||
*/
|
||||
protected function dispatch($eventName, Event $event = null)
|
||||
protected function dispatch($eventName, ActionEvent $event = null)
|
||||
{
|
||||
if ($event == null) $event = new DefaultActionEvent();
|
||||
|
||||
$this->getDispatcher()->dispatch($eventName, $event);
|
||||
}
|
||||
|
||||
@@ -145,7 +148,8 @@ class BaseController extends ContainerAware
|
||||
|
||||
/**
|
||||
*
|
||||
* redirect request to specify url
|
||||
* redirect request to the specified url
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
public function redirect($url)
|
||||
@@ -154,12 +158,21 @@ class BaseController extends ContainerAware
|
||||
}
|
||||
|
||||
/**
|
||||
* If success_url param is present in request, follow this link.
|
||||
* If success_url param is present in request or in the provided form, redirect to this URL.
|
||||
*
|
||||
* @param BaseForm $form a base form, which may contains the success URL
|
||||
*/
|
||||
protected function redirectSuccess()
|
||||
protected function redirectSuccess(BaseForm $form = null)
|
||||
{
|
||||
if (null !== $url = $this->getRequest()->get("success_url")) {
|
||||
$this->redirect($url);
|
||||
if ($form != null) {
|
||||
$url = $form->getSuccessUrl();
|
||||
}
|
||||
else {
|
||||
$url = $this->getRequest()->get("success_url");
|
||||
}
|
||||
|
||||
echo "url=$url";
|
||||
|
||||
if (null !== $url) $this->redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerLoginEvent;
|
||||
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
||||
@@ -37,65 +35,101 @@ use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Thelia\Core\Factory\ActionEventFactory;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Security\Exception\WrongPasswordException;
|
||||
|
||||
class CustomerController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* create a new Customer. Retrieve data in form and dispatch a action.createCustomer event
|
||||
*
|
||||
* if error occurs, message is set in the parserContext
|
||||
* Create a new customer.
|
||||
* On success, redirect to success_url if exists, otherwise, display the same view again.
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$customerCreation = new CustomerCreation($request);
|
||||
try {
|
||||
$form = $this->validateForm($customerCreation, "post");
|
||||
if (! $this->getSecurityContext()->hasCustomerUser()) {
|
||||
|
||||
$customerCreateEvent = $this->createEventInstance($form->getData());
|
||||
$message = false;
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
|
||||
$customerCreation = new CustomerCreation($this->getRequest());
|
||||
|
||||
$this->processLogin($customerCreateEvent->getCustomer());
|
||||
try {
|
||||
$form = $this->validateForm($customerCreation, "post");
|
||||
|
||||
$this->redirectSuccess();
|
||||
$customerCreateEvent = $this->createEventInstance($form->getData());
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$customerCreation->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->setErrorForm($customerCreation);
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during customer creation process in front context with message : %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
|
||||
|
||||
$this->processLogin($customerCreateEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess($customerCreation);
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
$message = "Invalid or missing data. Please check your input";
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$message = "Sorry, an unknown error occured.";
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage()));
|
||||
|
||||
$customerLoginForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->setErrorForm($customerLoginForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer data. On success, redirect to success_url if exists.
|
||||
* Otherwise, display the same view again.
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$customerModification = new CustomerModification($request);
|
||||
if ($this->getSecurityContext()->hasCustomerUser()) {
|
||||
|
||||
try {
|
||||
$message = false;
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
$customerModification = new CustomerModification($this->getRequest());
|
||||
|
||||
$form = $this->validateForm($customerModification, "post");
|
||||
try {
|
||||
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
$form = $this->validateForm($customerModification, "post");
|
||||
|
||||
$this->processLogin($customerChangeEvent->getCustomer());
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
|
||||
$this->redirectSuccess();
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$customerModification->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->setErrorForm($customerModification);
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during updating customer in front context with message : %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
$this->processLogin($customerChangeEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess($customerModification);
|
||||
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
$message = "Invalid or missing data. Please check your input";
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$message = "Sorry, an unknown error occured.";
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s. Exception was %s", $message, $e->getMessage()));
|
||||
|
||||
$customerLoginForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->setErrorForm($customerLoginForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,39 +137,75 @@ class CustomerController extends BaseFrontController
|
||||
* Perform user login. On a successful login, the user is redirected to the URL
|
||||
* found in the success_url form parameter, or / if none was found.
|
||||
*
|
||||
* If login is not successfull, the same view is dispolyed again.
|
||||
* If login is not successfull, the same view is displayed again.
|
||||
*
|
||||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if (! $this->getSecurityContext()->hasCustomerUser()) {
|
||||
$message = false;
|
||||
|
||||
$customerLoginForm = new CustomerLogin($request);
|
||||
$request = $this->getRequest();
|
||||
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
try {
|
||||
|
||||
try {
|
||||
$customer = $authenticator->getAuthentifiedUser();
|
||||
$customerLoginForm = new CustomerLogin($request);
|
||||
|
||||
$this->processLogin($customer);
|
||||
$form = $this->validateForm($customerLoginForm, "post");
|
||||
|
||||
$this->redirectSuccess();
|
||||
} catch (ValidatorException $e) {
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
|
||||
} catch(UsernameNotFoundException $e) {
|
||||
$customer = $authenticator->getAuthentifiedUser();
|
||||
|
||||
} catch(AuthenticationException $e) {
|
||||
$this->processLogin($customer);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->redirectSuccess($customerLoginForm);
|
||||
|
||||
}
|
||||
catch (FormValidationException $e) {
|
||||
$message = "Invalid or missing data. Please check your input";
|
||||
}
|
||||
catch(UsernameNotFoundException $e) {
|
||||
$message = "This customer email was not found.";
|
||||
}
|
||||
catch (WrongPasswordException $e) {
|
||||
$message = "Wrong password. Please try again.";
|
||||
}
|
||||
catch(AuthenticationException $e) {
|
||||
$message = "Sorry, we failed to authentify you. Please try again.";
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$message = "Sorry, an unknown error occured.";
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during customer login process : %s. Exception was %s", $message, $e->getMessage()));
|
||||
|
||||
$customerLoginForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()->setErrorForm($customerLoginForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processLogin(Customer $customer)
|
||||
/**
|
||||
* Perform customer logout.
|
||||
*
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
$this->getSecurityContext()->setCustomerUser($customer);
|
||||
if ($this->getSecurityContext()->hasCustomerUser()) {
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_LOGOUT);
|
||||
}
|
||||
|
||||
if($event) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer));
|
||||
// Redirect to home page
|
||||
$this->redirect(URL::getIndexPage());
|
||||
}
|
||||
|
||||
protected function processLogin(Customer $customer)
|
||||
{
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,10 +231,9 @@ class CustomerController extends BaseFrontController
|
||||
$this->getRequest()->getSession()->getLang(),
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:nullsch
|
||||
isset($data["discount"])?$data["discount"]:null
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user