Fixed module translations

This commit is contained in:
Franck Allimant
2014-04-22 12:12:53 +02:00
parent 7054b3d316
commit 9e0dedcb45
4 changed files with 624 additions and 626 deletions

View File

@@ -1,226 +1,227 @@
<?php <?php
/*************************************************************************************/ /*************************************************************************************/
/* */ /* */
/* Thelia */ /* Thelia */
/* */ /* */
/* Copyright (c) OpenStudio */ /* Copyright (c) OpenStudio */
/* email : info@thelia.net */ /* email : info@thelia.net */
/* web : http://www.thelia.net */ /* web : http://www.thelia.net */
/* */ /* */
/* This program is free software; you can redistribute it and/or modify */ /* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */ /* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */ /* the Free Software Foundation; either version 3 of the License */
/* */ /* */
/* This program is distributed in the hope that it will be useful, */ /* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */ /* GNU General Public License for more details. */
/* */ /* */
/* You should have received a copy of the GNU General Public License */ /* You should have received a copy of the GNU General Public License */
/* 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 Front\Controller; namespace Front\Controller;
use Thelia\Controller\Front\BaseFrontController; use Front\Front;
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Address\AddressEvent; use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Address\AddressEvent;
use Thelia\Core\Translation\Translator; use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\AddressCreateForm; use Thelia\Core\Translation\Translator;
use Thelia\Form\AddressUpdateForm; use Thelia\Form\AddressCreateForm;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\AddressUpdateForm;
use Thelia\Model\AddressQuery; use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer; use Thelia\Model\AddressQuery;
use Thelia\Model\Customer;
/**
* Class AddressController /**
* @package Thelia\Controller\Front * Class AddressController
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @package Thelia\Controller\Front
*/ * @author Manuel Raynaud <mraynaud@openstudio.fr>
class AddressController extends BaseFrontController */
{ class AddressController extends BaseFrontController
{
/**
* Controller for generate modal containing update form /**
* Check if request is a XmlHttpRequest and address owner is the current customer * Controller for generate modal containing update form
* @param $address_id * Check if request is a XmlHttpRequest and address owner is the current customer
*/ * @param $address_id
public function generateModalAction($address_id) */
{ public function generateModalAction($address_id)
{
$this->checkAuth();
$this->checkXmlHttpRequest(); $this->checkAuth();
$this->checkXmlHttpRequest();
}
}
/**
* Create controller. /**
* Check if customer is logged in * Create controller.
* * Check if customer is logged in
* Dispatch TheliaEvents::ADDRESS_CREATE event *
*/ * Dispatch TheliaEvents::ADDRESS_CREATE event
public function createAction() */
{ public function createAction()
{
$this->checkAuth();
$this->checkAuth();
$addressCreate = new AddressCreateForm($this->getRequest());
$addressCreate = new AddressCreateForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser(); try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressCreate, "post");
$event = $this->createAddressEvent($form); $form = $this->validateForm($addressCreate, "post");
$event->setCustomer($customer); $event = $this->createAddressEvent($form);
$event->setCustomer($customer);
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
$this->redirectSuccess($addressCreate); $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
$this->redirectSuccess($addressCreate);
} catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message)); if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressCreate->setErrorMessage($message);
$addressCreate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressCreate) $this->getParserContext()
->setGeneralError($message) ->addForm($addressCreate)
; ->setGeneralError($message)
} ;
} }
}
public function updateViewAction($address_id)
{ public function updateViewAction($address_id)
$this->checkAuth(); {
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id); $customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
$this->redirectToRoute('default'); if (!$address || $customer->getId() != $address->getCustomerId()) {
} $this->redirectToRoute('default');
}
$this->getParserContext()->set("address_id", $address_id);
} $this->getParserContext()->set("address_id", $address_id);
}
public function processUpdateAction($address_id)
{ public function processUpdateAction($address_id)
$this->checkAuth(); {
$request = $this->getRequest(); $this->checkAuth();
$request = $this->getRequest();
$addressUpdate = new AddressUpdateForm($request);
$addressUpdate = new AddressUpdateForm($request);
try {
$customer = $this->getSecurityContext()->getCustomerUser(); try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($addressUpdate);
$form = $this->validateForm($addressUpdate);
$address = AddressQuery::create()->findPk($address_id);
$address = AddressQuery::create()->findPk($address_id);
if (null === $address) {
$this->redirectToRoute('default'); if (null === $address) {
} $this->redirectToRoute('default');
}
if ($address->getCustomer()->getId() != $customer->getId()) {
$this->redirectToRoute('default'); if ($address->getCustomer()->getId() != $customer->getId()) {
} $this->redirectToRoute('default');
}
$event = $this->createAddressEvent($form);
$event->setAddress($address); $event = $this->createAddressEvent($form);
$event->setAddress($address);
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
$this->redirectSuccess($addressUpdate);
} catch (FormValidationException $e) { $this->redirectSuccess($addressUpdate);
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$this->getParserContext()->set("address_id", $address_id); }
if ($message !== false) { $this->getParserContext()->set("address_id", $address_id);
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message)); if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
$addressUpdate->setErrorMessage($message);
$addressUpdate->setErrorMessage($message);
$this->getParserContext()
->addForm($addressUpdate) $this->getParserContext()
->setGeneralError($message) ->addForm($addressUpdate)
; ->setGeneralError($message)
} ;
} }
}
public function deleteAction($address_id)
{ public function deleteAction($address_id)
$this->checkAuth(); {
$error_message = false; $this->checkAuth();
$error_message = false;
$customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id); $customer = $this->getSecurityContext()->getCustomerUser();
$address = AddressQuery::create()->findPk($address_id);
if (!$address || $customer->getId() != $address->getCustomerId()) {
// If Ajax Request if (!$address || $customer->getId() != $address->getCustomerId()) {
if ($this->getRequest()->isXmlHttpRequest()) { // If Ajax Request
return $this->jsonResponse(json_encode(array( if ($this->getRequest()->isXmlHttpRequest()) {
"success" => false, return $this->jsonResponse(json_encode(array(
"message" => "Error during address deletion process" "success" => false,
))); "message" => "Error during address deletion process"
} else { )));
$this->redirectToRoute('default'); } else {
} $this->redirectToRoute('default');
} }
}
try {
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address)); try {
} catch (\Exception $e) { $this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
$error_message = $e->getMessage(); } catch (\Exception $e) {
} $error_message = $e->getMessage();
}
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during address deletion : %s', $error_message));
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during address deletion : %s', $error_message));
// If Ajax Request
if ($this->getRequest()->isXmlHttpRequest()) { // If Ajax Request
if ($error_message) { if ($this->getRequest()->isXmlHttpRequest()) {
$response = $this->jsonResponse(json_encode(array( if ($error_message) {
"success" => false, $response = $this->jsonResponse(json_encode(array(
"message" => $error_message "success" => false,
))); "message" => $error_message
} else { )));
$response = $this->jsonResponse(json_encode(array( } else {
"success" => true, $response = $this->jsonResponse(json_encode(array(
"message" => "" "success" => true,
)));; "message" => ""
} )));;
}
return $response;
return $response;
} else {
$this->redirectToRoute('default', array('view'=>'account')); } else {
} $this->redirectToRoute('default', array('view'=>'account'));
} }
}
protected function createAddressEvent($form)
{ protected function createAddressEvent($form)
return new AddressCreateOrUpdateEvent( {
$form->get("label")->getData(), return new AddressCreateOrUpdateEvent(
$form->get("title")->getData(), $form->get("label")->getData(),
$form->get("firstname")->getData(), $form->get("title")->getData(),
$form->get("lastname")->getData(), $form->get("firstname")->getData(),
$form->get("address1")->getData(), $form->get("lastname")->getData(),
$form->get("address2")->getData(), $form->get("address1")->getData(),
$form->get("address3")->getData(), $form->get("address2")->getData(),
$form->get("zipcode")->getData(), $form->get("address3")->getData(),
$form->get("city")->getData(), $form->get("zipcode")->getData(),
$form->get("country")->getData(), $form->get("city")->getData(),
$form->get("cellphone")->getData(), $form->get("country")->getData(),
$form->get("phone")->getData(), $form->get("cellphone")->getData(),
$form->get("company")->getData(), $form->get("phone")->getData(),
$form->get("is_default")->getData() $form->get("company")->getData(),
); $form->get("is_default")->getData()
} );
} }
}

View File

@@ -1,391 +1,392 @@
<?php <?php
/*************************************************************************************/ /*************************************************************************************/
/* */ /* */
/* Thelia */ /* Thelia */
/* */ /* */
/* Copyright (c) OpenStudio */ /* Copyright (c) OpenStudio */
/* email : info@thelia.net */ /* email : info@thelia.net */
/* web : http://www.thelia.net */ /* web : http://www.thelia.net */
/* */ /* */
/* This program is free software; you can redistribute it and/or modify */ /* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */ /* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */ /* the Free Software Foundation; either version 3 of the License */
/* */ /* */
/* This program is distributed in the hope that it will be useful, */ /* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */ /* GNU General Public License for more details. */
/* */ /* */
/* You should have received a copy of the GNU General Public License */ /* You should have received a copy of the GNU General Public License */
/* 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 Front\Controller; namespace Front\Controller;
use Thelia\Controller\Front\BaseFrontController; use Front\Front;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Customer\CustomerLoginEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\LostPasswordEvent; use Thelia\Core\Event\Customer\CustomerLoginEvent;
use Thelia\Core\Event\Newsletter\NewsletterEvent; use Thelia\Core\Event\LostPasswordEvent;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator; use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\Exception\UsernameNotFoundException; use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Translation\Translator; use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Thelia\Form\CustomerCreateForm; use Thelia\Core\Translation\Translator;
use Thelia\Form\CustomerLogin; use Thelia\Form\CustomerCreateForm;
use Thelia\Form\CustomerLostPasswordForm; use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerPasswordUpdateForm; use Thelia\Form\CustomerLostPasswordForm;
use Thelia\Form\CustomerProfileUpdateForm; use Thelia\Form\CustomerPasswordUpdateForm;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\CustomerProfileUpdateForm;
use Thelia\Model\Customer; use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Customer;
use Thelia\Model\NewsletterQuery; use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL; use Thelia\Model\NewsletterQuery;
use Thelia\Log\Tlog; use Thelia\Tools\URL;
use Thelia\Core\Security\Exception\WrongPasswordException; use Thelia\Log\Tlog;
use Thelia\Core\Security\Exception\WrongPasswordException;
/**
* Class CustomerController /**
* @package Thelia\Controller\Front * Class CustomerController
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @package Thelia\Controller\Front
*/ * @author Manuel Raynaud <mraynaud@openstudio.fr>
class CustomerController extends BaseFrontController */
{ class CustomerController extends BaseFrontController
use \Thelia\Cart\CartTrait; {
use \Thelia\Cart\CartTrait;
public function newPasswordAction()
{ public function newPasswordAction()
if (! $this->getSecurityContext()->hasCustomerUser()) { {
$message = false; if (! $this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$passwordLost = new CustomerLostPasswordForm($this->getRequest());
$passwordLost = new CustomerLostPasswordForm($this->getRequest());
try {
try {
$form = $this->validateForm($passwordLost);
$form = $this->validateForm($passwordLost);
$event = new LostPasswordEvent($form->get("email")->getData());
$event = new LostPasswordEvent($form->get("email")->getData());
$this->dispatch(TheliaEvents::LOST_PASSWORD, $event);
$this->dispatch(TheliaEvents::LOST_PASSWORD, $event);
} catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage())); if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage()));
$passwordLost->setErrorMessage($message);
$passwordLost->setErrorMessage($message);
$this->getParserContext()
->addForm($passwordLost) $this->getParserContext()
->setGeneralError($message) ->addForm($passwordLost)
; ->setGeneralError($message)
} ;
} }
} }
}
/**
* Create a new customer. /**
* On success, redirect to success_url if exists, otherwise, display the same view again. * Create a new customer.
*/ * On success, redirect to success_url if exists, otherwise, display the same view again.
public function createAction() */
{ public function createAction()
if (! $this->getSecurityContext()->hasCustomerUser()) { {
if (! $this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$message = false;
$customerCreation = new CustomerCreateForm($this->getRequest());
$customerCreation = new CustomerCreateForm($this->getRequest());
try {
$form = $this->validateForm($customerCreation, "post"); try {
$form = $this->validateForm($customerCreation, "post");
$customerCreateEvent = $this->createEventInstance($form->getData());
$customerCreateEvent = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
$newCustomer = $customerCreateEvent->getCustomer();
$newCustomer = $customerCreateEvent->getCustomer();
// Newsletter
if (true === $form->get('newsletter')->getData()) { // Newsletter
$newsletterEmail = $newCustomer->getEmail(); if (true === $form->get('newsletter')->getData()) {
$nlEvent = new NewsletterEvent($newsletterEmail, $this->getRequest()->getSession()->getLang()->getLocale()); $newsletterEmail = $newCustomer->getEmail();
$nlEvent->setFirstname($newCustomer->getFirstname()); $nlEvent = new NewsletterEvent($newsletterEmail, $this->getRequest()->getSession()->getLang()->getLocale());
$nlEvent->setLastname($newCustomer->getLastname()); $nlEvent->setFirstname($newCustomer->getFirstname());
$nlEvent->setLastname($newCustomer->getLastname());
// Security : Check if this new Email address already exist
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterEmail)) { // Security : Check if this new Email address already exist
$nlEvent->setId($newsletter->getId()); if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterEmail)) {
$this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent); $nlEvent->setId($newsletter->getId());
} else { $this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent);
$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent); } else {
} $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent);
} }
}
$this->processLogin($customerCreateEvent->getCustomer());
$this->processLogin($customerCreateEvent->getCustomer());
$cart = $this->getCart($this->getDispatcher(), $this->getRequest());
if ($cart->getCartItems()->count() > 0) { $cart = $this->getCart($this->getDispatcher(), $this->getRequest());
$this->redirectToRoute('cart.view'); if ($cart->getCartItems()->count() > 0) {
} else { $this->redirectToRoute('cart.view');
$this->redirectSuccess($customerCreation); } else {
} $this->redirectSuccess($customerCreation);
} catch (FormValidationException $e) { }
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage())); if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer creation process : %s. Exception was %s", $message, $e->getMessage()));
$customerCreation->setErrorMessage($message);
$customerCreation->setErrorMessage($message);
$this->getParserContext()
->addForm($customerCreation) $this->getParserContext()
->setGeneralError($message) ->addForm($customerCreation)
; ->setGeneralError($message)
} ;
} }
} }
}
/**
* Update customer data. On success, redirect to success_url if exists. /**
* Otherwise, display the same view again. * Update customer data. On success, redirect to success_url if exists.
*/ * Otherwise, display the same view again.
public function viewAction() */
{ public function viewAction()
$this->checkAuth(); {
$this->checkAuth();
$customer = $this->getSecurityContext()->getCustomerUser();
$data = array( $customer = $this->getSecurityContext()->getCustomerUser();
'id' => $customer->getId(), $data = array(
'title' => $customer->getTitleId(), 'id' => $customer->getId(),
'firstname' => $customer->getFirstName(), 'title' => $customer->getTitleId(),
'lastname' => $customer->getLastName(), 'firstname' => $customer->getFirstName(),
'email' => $customer->getEmail(), 'lastname' => $customer->getLastName(),
'newsletter' => null !== NewsletterQuery::create()->findOneByEmail($customer->getEmail()), 'email' => $customer->getEmail(),
); 'newsletter' => null !== NewsletterQuery::create()->findOneByEmail($customer->getEmail()),
);
$customerProfileUpdateForm = new CustomerProfileUpdateForm($this->getRequest(), 'form', $data);
$customerProfileUpdateForm = new CustomerProfileUpdateForm($this->getRequest(), 'form', $data);
// Pass it to the parser
$this->getParserContext()->addForm($customerProfileUpdateForm); // Pass it to the parser
} $this->getParserContext()->addForm($customerProfileUpdateForm);
}
public function updatePasswordAction()
{ public function updatePasswordAction()
if ($this->getSecurityContext()->hasCustomerUser()) { {
$message = false; if ($this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$customerPasswordUpdateForm = new CustomerPasswordUpdateForm($this->getRequest());
$customerPasswordUpdateForm = new CustomerPasswordUpdateForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser(); try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($customerPasswordUpdateForm, "post");
$form = $this->validateForm($customerPasswordUpdateForm, "post");
$customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer); $customerChangeEvent = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFILE, $customerChangeEvent); $customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFILE, $customerChangeEvent);
$this->redirectSuccess($customerPasswordUpdateForm);
$this->redirectSuccess($customerPasswordUpdateForm);
} catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer password modification process : %s.", $message)); if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer password modification process : %s.", $message));
$customerPasswordUpdateForm->setErrorMessage($message);
$customerPasswordUpdateForm->setErrorMessage($message);
$this->getParserContext()
->addForm($customerPasswordUpdateForm) $this->getParserContext()
->setGeneralError($message) ->addForm($customerPasswordUpdateForm)
; ->setGeneralError($message)
} ;
} }
} }
}
public function updateAction()
{ public function updateAction()
if ($this->getSecurityContext()->hasCustomerUser()) { {
if ($this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$message = false;
$customerProfileUpdateForm = new CustomerProfileUpdateForm($this->getRequest());
$customerProfileUpdateForm = new CustomerProfileUpdateForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser(); try {
$newsletterOldEmail = $customer->getEmail(); $customer = $this->getSecurityContext()->getCustomerUser();
$newsletterOldEmail = $customer->getEmail();
$form = $this->validateForm($customerProfileUpdateForm, "post");
$form = $this->validateForm($customerProfileUpdateForm, "post");
$customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer); $customerChangeEvent = $this->createEventInstance($form->getData());
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFILE, $customerChangeEvent); $customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFILE, $customerChangeEvent);
$updatedCustomer = $customerChangeEvent->getCustomer();
$updatedCustomer = $customerChangeEvent->getCustomer();
// Newsletter
if (true === $form->get('newsletter')->getData()) { // Newsletter
$nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale()); if (true === $form->get('newsletter')->getData()) {
$nlEvent->setFirstname($updatedCustomer->getFirstname()); $nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale());
$nlEvent->setLastname($updatedCustomer->getLastname()); $nlEvent->setFirstname($updatedCustomer->getFirstname());
$nlEvent->setLastname($updatedCustomer->getLastname());
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
$nlEvent->setId($newsletter->getId()); if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
$this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent); $nlEvent->setId($newsletter->getId());
} else { $this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent);
$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent); } else {
} $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent);
} else { }
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) { } else {
$nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale()); if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
$nlEvent->setId($newsletter->getId()); $nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale());
$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $nlEvent); $nlEvent->setId($newsletter->getId());
} $this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $nlEvent);
} }
}
$this->processLogin($updatedCustomer);
$this->processLogin($updatedCustomer);
$this->redirectSuccess($customerProfileUpdateForm);
$this->redirectSuccess($customerProfileUpdateForm);
} catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message)); if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
$customerProfileUpdateForm->setErrorMessage($message);
$customerProfileUpdateForm->setErrorMessage($message);
$this->getParserContext()
->addForm($customerProfileUpdateForm) $this->getParserContext()
->setGeneralError($message) ->addForm($customerProfileUpdateForm)
; ->setGeneralError($message)
} ;
} }
} }
}
/**
* 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. * 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 displayed again. *
* * If login is not successfull, the same view is displayed again.
*/ *
public function loginAction() */
{ public function loginAction()
if (! $this->getSecurityContext()->hasCustomerUser()) { {
$message = false; if (! $this->getSecurityContext()->hasCustomerUser()) {
$message = false;
$request = $this->getRequest();
$customerLoginForm = new CustomerLogin($request); $request = $this->getRequest();
$customerLoginForm = new CustomerLogin($request);
try {
try {
$form = $this->validateForm($customerLoginForm, "post");
$form = $this->validateForm($customerLoginForm, "post");
// If User is a new customer
if ($form->get('account')->getData() == 0 && !$form->get("email")->getErrors()) { // If User is a new customer
$this->redirectToRoute("customer.create.process", array("email" => $form->get("email")->getData())); if ($form->get('account')->getData() == 0 && !$form->get("email")->getErrors()) {
} else { $this->redirectToRoute("customer.create.process", array("email" => $form->get("email")->getData()));
} else {
try {
try {
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
$customer = $authenticator->getAuthentifiedUser();
$customer = $authenticator->getAuthentifiedUser();
$this->processLogin($customer);
$this->processLogin($customer);
$this->redirectSuccess($customerLoginForm);
$this->redirectSuccess($customerLoginForm);
} catch (UsernameNotFoundException $e) {
$message = "Wrong email or password. Please try again"; } catch (UsernameNotFoundException $e) {
} catch (WrongPasswordException $e) { $message = "Wrong email or password. Please try again";
$message = "Wrong email or password. Please try again"; } catch (WrongPasswordException $e) {
} catch (AuthenticationException $e) { $message = "Wrong email or password. Please try again";
$message = "Wrong email or password. Please try again"; } catch (AuthenticationException $e) {
} $message = "Wrong email or password. Please try again";
}
}
}
} catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); } catch (FormValidationException $e) {
} catch (\Exception $e) { $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); } catch (\Exception $e) {
} $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
}
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer login process : %s. Exception was %s", $message, $e->getMessage())); if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer login process : %s. Exception was %s", $message, $e->getMessage()));
$customerLoginForm->setErrorMessage($message);
$customerLoginForm->setErrorMessage($message);
$this->getParserContext()->addForm($customerLoginForm);
} $this->getParserContext()->addForm($customerLoginForm);
} }
} }
}
/**
* Perform customer logout. /**
*/ * Perform customer logout.
public function logoutAction() */
{ public function logoutAction()
if ($this->getSecurityContext()->hasCustomerUser()) { {
$this->dispatch(TheliaEvents::CUSTOMER_LOGOUT); if ($this->getSecurityContext()->hasCustomerUser()) {
} $this->dispatch(TheliaEvents::CUSTOMER_LOGOUT);
}
// Redirect to home page
$this->redirect(URL::getInstance()->getIndexPage()); // Redirect to home page
} $this->redirect(URL::getInstance()->getIndexPage());
}
/**
* Dispatch event for customer login action /**
* * Dispatch event for customer login action
* @param Customer $customer *
*/ * @param Customer $customer
protected function processLogin(Customer $customer) */
{ protected function processLogin(Customer $customer)
$this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer)); {
} $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer));
}
/**
* @param $data /**
* @return \Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent * @param $data
*/ * @return \Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent
private function createEventInstance($data) */
{ private function createEventInstance($data)
$customerCreateEvent = new CustomerCreateOrUpdateEvent( {
isset($data["title"])?$data["title"]:null, $customerCreateEvent = new CustomerCreateOrUpdateEvent(
isset($data["firstname"])?$data["firstname"]:null, isset($data["title"])?$data["title"]:null,
isset($data["lastname"])?$data["lastname"]:null, isset($data["firstname"])?$data["firstname"]:null,
isset($data["address1"])?$data["address1"]:null, isset($data["lastname"])?$data["lastname"]:null,
isset($data["address2"])?$data["address2"]:null, isset($data["address1"])?$data["address1"]:null,
isset($data["address3"])?$data["address3"]:null, isset($data["address2"])?$data["address2"]:null,
isset($data["phone"])?$data["phone"]:null, isset($data["address3"])?$data["address3"]:null,
isset($data["cellphone"])?$data["cellphone"]:null, isset($data["phone"])?$data["phone"]:null,
isset($data["zipcode"])?$data["zipcode"]:null, isset($data["cellphone"])?$data["cellphone"]:null,
isset($data["city"])?$data["city"]:null, isset($data["zipcode"])?$data["zipcode"]:null,
isset($data["country"])?$data["country"]:null, isset($data["city"])?$data["city"]:null,
isset($data["email"])?$data["email"]:null, isset($data["country"])?$data["country"]:null,
isset($data["password"]) ? $data["password"]:null, isset($data["email"])?$data["email"]:null,
$this->getRequest()->getSession()->getLang()->getId(), isset($data["password"]) ? $data["password"]:null,
isset($data["reseller"])?$data["reseller"]:null, $this->getRequest()->getSession()->getLang()->getId(),
isset($data["sponsor"])?$data["sponsor"]:null, isset($data["reseller"])?$data["reseller"]:null,
isset($data["discount"])?$data["discount"]:null, isset($data["sponsor"])?$data["sponsor"]:null,
isset($data["company"])?$data["company"]:null, isset($data["discount"])?$data["discount"]:null,
null isset($data["company"])?$data["company"]:null,
); null
);
return $customerCreateEvent;
} return $customerCreateEvent;
} }
}

View File

@@ -102,11 +102,11 @@ class OrderController extends BaseFrontController
$this->redirectToRoute("order.invoice"); $this->redirectToRoute("order.invoice");
} catch (FormValidationException $e) { } catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (PropelException $e) { } catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage()); $this->getParserContext()->setGeneralError($e->getMessage());
} catch (\Exception $e) { } catch (\Exception $e) {
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} }
if ($message !== false) { if ($message !== false) {
@@ -158,11 +158,11 @@ class OrderController extends BaseFrontController
$this->redirectToRoute("order.payment.process"); $this->redirectToRoute("order.payment.process");
} catch (FormValidationException $e) { } catch (FormValidationException $e) {
$message = sprintf(Translator::getInstance()->trans("Please check your input: %s"), $e->getMessage()); $message = Translator::getInstance()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} catch (PropelException $e) { } catch (PropelException $e) {
$this->getParserContext()->setGeneralError($e->getMessage()); $this->getParserContext()->setGeneralError($e->getMessage());
} catch (\Exception $e) { } catch (\Exception $e) {
$message = sprintf(Translator::getInstance()->trans("Sorry, an error occured: %s"), $e->getMessage()); $message = Translator::getInstance()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
} }
if ($message !== false) { if ($message !== false) {

View File

@@ -27,9 +27,5 @@ use Thelia\Module\BaseModule;
class Front extends BaseModule class Front extends BaseModule
{ {
/** const MESSAGE_DOMAIN = 'front';
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
* Like install and destroy
*/
} }