Merge branch 'frontend' of github.com:thelia/thelia into frontend

This commit is contained in:
badsuricate
2013-10-24 09:12:52 +02:00
16 changed files with 136 additions and 52 deletions

View File

@@ -60,6 +60,27 @@ class Customer extends BaseAction implements EventSubscriberInterface
}
public function updateProfil(CustomerCreateOrUpdateEvent $event)
{
$customer = $event->getCustomer();
$customer->setDispatcher($this->getDispatcher());
$customer
->setTitleId($event->getTitle())
->setFirstname($event->getFirstname())
->setLastname($event->getLastname())
->setEmail($event->getEmail())
->setPassword($event->getPassword())
->setReseller($event->getReseller())
->setSponsor($event->getSponsor())
->setDiscount($event->getDiscount())
->save();
$event->setCustomer($customer);
}
public function delete(CustomerEvent $event)
{
$customer = $event->getCustomer();
@@ -110,11 +131,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
$this->getSecurityContext()->clearCustomerUser();
}
public function changePassword(ActionEvent $event)
{
// TODO
}
/**
* Return the security context
*
@@ -150,6 +166,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
return array(
TheliaEvents::CUSTOMER_CREATEACCOUNT => array('create', 128),
TheliaEvents::CUSTOMER_UPDATEACCOUNT => array('modify', 128),
TheliaEvents::CUSTOMER_UPDATEPROFIL => array('updateProfil', 128),
TheliaEvents::CUSTOMER_LOGOUT => array('logout', 128),
TheliaEvents::CUSTOMER_LOGIN => array('login', 128),
TheliaEvents::CUSTOMER_DELETEACCOUNT => array('delete', 128),

View File

@@ -49,6 +49,11 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
->save();
}
public function unsubscribe(NewsletterEvent $event)
{
// TODO
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
@@ -72,7 +77,8 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
TheliaEvents::NEWSLETTER_SUBSCRIBE => array('subscribe', 128)
TheliaEvents::NEWSLETTER_SUBSCRIBE => array('subscribe', 128),
TheliaEvents::NEWSLETTER_UNSUBSCRIBE => array('unsubscribe', 128)
);
}
}

View File

@@ -32,11 +32,11 @@ use Thelia\Form\CustomerCreateForm;
use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerLostPasswordForm;
use Thelia\Form\CustomerPasswordUpdateForm;
use Thelia\Form\CustomerUpdateForm;
use Thelia\Form\CustomerProfilUpdateForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\CustomerQuery;
use Thelia\Model\NewsletterQuery;
use Thelia\Tools\URL;
use Thelia\Log\Tlog;
use Thelia\Core\Security\Exception\WrongPasswordException;
@@ -131,12 +131,6 @@ class CustomerController extends BaseFrontController
}
}
protected function getExistingCustomer($customer_id)
{
return CustomerQuery::create()
->findOneById($customer_id);
}
/**
* Update customer data. On success, redirect to success_url if exists.
* Otherwise, display the same view again.
@@ -152,12 +146,13 @@ class CustomerController extends BaseFrontController
'firstname' => $customer->getFirstName(),
'lastname' => $customer->getLastName(),
'email' => $customer->getEmail(),
'newsletter' => NewsletterQuery::isSubscribed($customer->getEmail())
);
$customerUpdateForm = new CustomerUpdateForm($this->getRequest(), 'form', $data);
$customerProfilUpdateForm = new CustomerProfilUpdateForm($this->getRequest(), 'form', $data);
// Pass it to the parser
$this->getParserContext()->addForm($customerUpdateForm);
$this->getParserContext()->addForm($customerProfilUpdateForm);
}
@@ -175,7 +170,7 @@ class CustomerController extends BaseFrontController
$customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer);
//$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFIL, $customerChangeEvent);
$this->redirectSuccess($customerPasswordUpdateForm);
@@ -204,21 +199,27 @@ class CustomerController extends BaseFrontController
$message = false;
$customerUpdateForm = new CustomerUpdateForm($this->getRequest());
$customerProfilUpdateForm = new CustomerProfilUpdateForm($this->getRequest());
try {
$customer = $this->getSecurityContext()->getCustomerUser();
$form = $this->validateForm($customerUpdateForm, "post");
$form = $this->validateForm($customerProfilUpdateForm, "post");
$customerChangeEvent = $this->createEventInstance($form->getData());
$customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFIL, $customerChangeEvent);
// Newsletter
if ($form->get('newsletter')->getData()){
//$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $customerChangeEvent);
} else {
//$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $customerChangeEvent);
}
$this->processLogin($customerChangeEvent->getCustomer());
$this->redirectSuccess($customerUpdateForm);
$this->redirectSuccess($customerProfilUpdateForm);
} catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
@@ -229,10 +230,10 @@ class CustomerController extends BaseFrontController
if ($message !== false) {
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
$customerUpdateForm->setErrorMessage($message);
$customerProfilUpdateForm->setErrorMessage($message);
$this->getParserContext()
->addForm($customerUpdateForm)
->addForm($customerProfilUpdateForm)
->setGeneralError($message)
;
}
@@ -329,9 +330,9 @@ class CustomerController extends BaseFrontController
private function createEventInstance($data)
{
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
$data["title"],
$data["firstname"],
$data["lastname"],
isset($data["title"])?$data["title"]:null,
isset($data["firstname"])?$data["firstname"]:null,
isset($data["lastname"])?$data["lastname"]:null,
isset($data["address1"])?$data["address1"]:null,
isset($data["address2"])?$data["address2"]:null,
isset($data["address3"])?$data["address3"]:null,

View File

@@ -71,6 +71,11 @@ final class TheliaEvents
*/
const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer";
/**
* sent on customer account update profil
*/
const CUSTOMER_UPDATEPROFIL = "action.updateProfilCustomer";
/**
* sent on customer removal
*/
@@ -686,4 +691,9 @@ final class TheliaEvents
* sent for subscribing to the newsletter
*/
const NEWSLETTER_SUBSCRIBE = 'thelia.newsletter.subscribe';
/**
* sent for subscribing to the newsletter
*/
const NEWSLETTER_UNSUBSCRIBE = 'thelia.newsletter.unsubscribe';
}

View File

@@ -111,7 +111,7 @@ class CustomerCreateForm extends AddressCreateForm
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::create()->findOneByEmail($value);
$customer = CustomerQuery::getCustomerByEmail($value);
if ($customer) {
$context->addViolation("This email already exists.");
}

View File

@@ -26,6 +26,7 @@ use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerPasswordUpdateForm
@@ -79,7 +80,10 @@ class CustomerPasswordUpdateForm extends BaseForm
public function verifyCurrentPasswordField($value, ExecutionContextInterface $context)
{
// Check current password
// Check if value of the old password match the password of the current user
if (!password_verify($value, $this->getRequest()->getSession()->getCustomerUser()->getPassword())) {
$context->addViolation("Your current password does not match.");
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)

View File

@@ -23,6 +23,8 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\CustomerQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
@@ -51,6 +53,9 @@ class CustomerProfilUpdateForm extends CustomerCreateForm
->remove("city")
->remove("zipcode")
->remove("country")
// Remove Login Information
->remove("password")
->remove("password_confirm")
// Remove Terms & conditions
->remove("agreed")
@@ -64,6 +69,20 @@ class CustomerProfilUpdateForm extends CustomerCreateForm
));
}
/**
* @param $value
* @param ExecutionContextInterface $context
*/
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::getCustomerByEmail($value);
// If there is already a customer for this email address and if the customer is different from the current user, do a violation
if ($customer && $customer->getId() != $this->getRequest()->getSession()->getCustomerUser()->getId()) {
$context->addViolation("This email already exists.");
}
}
public function getName()
{
return "thelia_customer_profil_update";

View File

@@ -17,4 +17,8 @@ use Thelia\Model\Base\CustomerQuery as BaseCustomerQuery;
*/
class CustomerQuery extends BaseCustomerQuery {
public static function getCustomerByEmail($email)
{
return self::create()->findOneByEmail($email);
}
} // CustomerQuery

View File

@@ -17,5 +17,8 @@ use Thelia\Model\Base\NewsletterQuery as BaseNewsletterQuery;
*/
class NewsletterQuery extends BaseNewsletterQuery
{
public static function isSubscribed($email)
{
return (null === self::create()->findOneByEmail($email)) ? false : true;
}
} // NewsletterQuery