Merge branch 'master' into loops

Conflicts:
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Loop/FeatureValue.php
	core/lib/Thelia/Core/Template/Loop/Folder.php
	core/lib/Thelia/Core/Template/Loop/Product.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	install/faker.php
This commit is contained in:
Etienne Roudeix
2013-08-21 09:19:56 +02:00
3275 changed files with 929970 additions and 274940 deletions

147
documentation/api/files/Action/Customer.php.txt Normal file → Executable file
View File

@@ -25,9 +25,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\BaseForm;
use Thelia\Form\CustomerCreation;
use Thelia\Form\CustomerModification;
use Thelia\Model\Customer as CustomerModel;
@@ -35,42 +33,30 @@ use Thelia\Log\Tlog;
use Thelia\Model\CustomerQuery;
use Thelia\Form\CustomerLogin;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\SecurityContext;
use Thelia\Model\ConfigQuery;
use Symfony\Component\Validator\Exception\ValidatorException;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Propel\Runtime\Exception\PropelException;
use Thelia\Action\Exception\FormValidationException;
class Customer extends BaseAction implements EventSubscriberInterface
{
/**
* @var Thelia\Core\Security\SecurityContext
*/
protected $securityContext;
public function __construct(SecurityContext $securityContext) {
$this->securityContext = $securityContext;
}
public function create(ActionEvent $event)
{
$request = $event->getRequest();
$request = $event->getRequest();
try {
$customerCreationForm = new CustomerCreation($request);
try {
$customerCreationForm = new CustomerCreation($request);
$form = $this->validateForm($customerCreationForm, "POST");
$form = $this->validateForm($customerCreationForm, "POST");
$data = $form->getData();
$customer = new CustomerModel();
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $event);
$customer = new CustomerModel();
$customer->setDispatcher($event->getDispatcher());
$customer->createOrUpdate(
$data["title"],
$data["title"],
$data["firstname"],
$data["lastname"],
$data["address1"],
@@ -85,42 +71,35 @@ class Customer extends BaseAction implements EventSubscriberInterface
$request->getSession()->getLang()
);
$customerEvent = new CustomerEvent($customer);
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent);
$event->customer = $customer;
} catch (PropelException $e) {
// Connect the newly created user,and redirect to the success URL
$this->processSuccessfullLogin($event, $customer, $customerCreationForm, true);
}
catch (PropelException $e) {
Tlog::getInstance()->error(sprintf('error during creating customer on action/createCustomer with message "%s"', $e->getMessage()));
$message = "Failed to create your account, please try again.";
}
catch(FormValidationException $e) {
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// The form has errors, propagate it.
$this->propagateFormError($customerCreationForm, $message, $event);
}
}
public function modify(ActionEvent $event)
{
$request = $event->getRequest();
$request = $event->getRequest();
try {
$customerModification = new CustomerModification($request);
try {
$customerModification = new CustomerModification($request);
$form = $this->validateForm($customerModification, "POST");
$form = $this->validateForm($customerModification, "POST");
$data = $form->getData();
$customer = CustomerQuery::create()->findPk(1);
$customerEvent = new CustomerEvent($customer);
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent);
$data = $form->getData();
$customer->createOrUpdate(
@@ -134,30 +113,24 @@ class Customer extends BaseAction implements EventSubscriberInterface
$data["cellphone"],
$data["zipcode"],
$data["country"]
);
$customerEvent->customer = $customer;
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent);
);
// Update the logged-in user, and redirect to the success URL (exits)
// We don-t send the login event, as the customer si already logged.
$this->processSuccessfullLogin($event, $customer, $customerModification);
}
catch(PropelException $e) {
} catch (PropelException $e) {
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
$message = "Failed to change your account, please try again.";
}
catch(FormValidationException $e) {
} catch (FormValidationException $e) {
$message = $e->getMessage();
}
// The form has errors, propagate it.
$this->propagateFormError($customerModification, $message, $event);
}
}
/**
* Perform user logout. The user is redirected to the provided view, if any.
@@ -166,9 +139,9 @@ class Customer extends BaseAction implements EventSubscriberInterface
*/
public function logout(ActionEvent $event)
{
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
$this->getSecurityContext()->clear();
$this->getFrontSecurityContext()->clear();
}
/**
@@ -181,36 +154,33 @@ class Customer extends BaseAction implements EventSubscriberInterface
*/
public function login(ActionEvent $event)
{
$request = $event->getRequest();
$request = $event->getRequest();
$customerLoginForm = new CustomerLogin($request);
$customerLoginForm = new CustomerLogin($request);
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
try {
$user = $authenticator->getAuthentifiedUser();
try {
$user = $authenticator->getAuthentifiedUser();
$this->processSuccessfullLogin($event, $user, $customerLoginForm);
}
catch (ValidatorException $ex) {
$message = "Missing or invalid information. Please check your input.";
}
catch (UsernameNotFoundException $ex) {
$message = "This email address was not found.";
}
catch (AuthenticationException $ex) {
$message = "Login failed. Please check your username and password.";
}
catch (\Exception $ex) {
$message = sprintf("Unable to process your request. Please try again (%s in %s).", $ex->getMessage(), $ex->getFile());
}
$event->customer = $customer;
// The for has an error
$customerLoginForm->setError(true);
$customerLoginForm->setErrorMessage($message);
} catch (ValidatorException $ex) {
$message = "Missing or invalid information. Please check your input.";
} catch (UsernameNotFoundException $ex) {
$message = "This email address was not found.";
} catch (AuthenticationException $ex) {
$message = "Login failed. Please check your username and password.";
} catch (\Exception $ex) {
$message = sprintf("Unable to process your request. Please try again (%s in %s).", $ex->getMessage(), $ex->getFile());
}
// Dispatch the errored form
$event->setErrorForm($customerLoginForm);
// The for has an error
$customerLoginForm->setError(true);
$customerLoginForm->setErrorMessage($message);
// Dispatch the errored form
$event->setErrorForm($customerLoginForm);
// A this point, the same view is displayed again.
}
@@ -249,32 +219,5 @@ class Customer extends BaseAction implements EventSubscriberInterface
"action.logoutCustomer" => array("logout", 128),
);
}
/**
* Stores the current user in the security context, and redirect to the
* success_url.
*
* @param CustomerModel $user the logged user
*/
protected function processSuccessfullLogin(ActionEvent $event, CustomerModel $user, BaseForm $form, $sendLoginEvent = false)
{
// Success -> store user in security context
$this->getSecurityContext()->setUser($user);
if ($sendLoginEvent) $event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
// Redirect to the success URL
$this->redirect($form->getSuccessUrl());
}
/**
* Return the security context, beeing sure that we're in the CONTEXT_FRONT_OFFICE context
*
* @return SecurityContext the security context
*/
protected function getSecurityContext() {
$this->securityContext->setContext(SecurityContext::CONTEXT_FRONT_OFFICE);
return $this->securityContext;
}
}