From a91303a27ddc4298aaefcd301192c61bd0dff5e8 Mon Sep 17 00:00:00 2001 From: touffies Date: Wed, 23 Oct 2013 00:07:27 +0200 Subject: [PATCH] Add new method updatePasswordAction (Not finished) --- .../Thelia/Config/Resources/routing/front.xml | 2 +- .../Controller/Front/CustomerController.php | 40 +++++++++++++++++++ core/lib/Thelia/Form/CustomerLogin.php | 2 - .../Form/CustomerPasswordUpdateForm.php | 5 +-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index cf8ea636e..97ddce393 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -76,7 +76,7 @@ - Thelia\Controller\Front\CustomerController::newPasswordAction + Thelia\Controller\Front\CustomerController::updatePasswordAction account-password diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php index 9c43edce1..fa5a9e3a3 100755 --- a/core/lib/Thelia/Controller/Front/CustomerController.php +++ b/core/lib/Thelia/Controller/Front/CustomerController.php @@ -31,6 +31,7 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException; use Thelia\Form\CustomerCreateForm; use Thelia\Form\CustomerLogin; use Thelia\Form\CustomerLostPasswordForm; +use Thelia\Form\CustomerPasswordUpdateForm; use Thelia\Form\CustomerUpdateForm; use Thelia\Form\Exception\FormValidationException; use Thelia\Model\Customer; @@ -49,6 +50,7 @@ class CustomerController extends BaseFrontController { use \Thelia\Cart\CartTrait; + public function newPasswordAction() { if (! $this->getSecurityContext()->hasCustomerUser()) { @@ -158,6 +160,44 @@ class CustomerController extends BaseFrontController $this->getParserContext()->addForm($customerUpdateForm); } + + public function updatePasswordAction() + { + if ($this->getSecurityContext()->hasCustomerUser()) { + $message = false; + + $customerPasswordUpdateForm = new CustomerPasswordUpdateForm($this->getRequest()); + + try { + $customer = $this->getSecurityContext()->getCustomerUser(); + + $form = $this->validateForm($customerPasswordUpdateForm, "post"); + + $customerChangeEvent = $this->createEventInstance($form->getData()); + $customerChangeEvent->setCustomer($customer); + //$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent); + + $this->redirectSuccess($customerPasswordUpdateForm); + + } catch (FormValidationException $e) { + $message = sprintf("Please check your input: %s", $e->getMessage()); + } catch (\Exception $e) { + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); + } + + if ($message !== false) { + Tlog::getInstance()->error(sprintf("Error during customer password modification process : %s.", $message)); + + $customerPasswordUpdateForm->setErrorMessage($message); + + $this->getParserContext() + ->addForm($customerPasswordUpdateForm) + ->setGeneralError($message) + ; + } + } + } + public function updateAction() { if ($this->getSecurityContext()->hasCustomerUser()) { diff --git a/core/lib/Thelia/Form/CustomerLogin.php b/core/lib/Thelia/Form/CustomerLogin.php index 055c0bc29..66b5c34ef 100755 --- a/core/lib/Thelia/Form/CustomerLogin.php +++ b/core/lib/Thelia/Form/CustomerLogin.php @@ -22,8 +22,6 @@ /*************************************************************************************/ namespace Thelia\Form; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Email; diff --git a/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php b/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php index b8310d697..78e1218ff 100755 --- a/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php +++ b/core/lib/Thelia/Form/CustomerPasswordUpdateForm.php @@ -25,7 +25,6 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Model\ConfigQuery; -use Thelia\Model\CustomerQuery; use Thelia\Core\Translation\Translator; /** @@ -80,7 +79,7 @@ class CustomerPasswordUpdateForm extends BaseForm public function verifyCurrentPasswordField($value, ExecutionContextInterface $context) { - + // Check current password } public function verifyPasswordField($value, ExecutionContextInterface $context) @@ -88,7 +87,7 @@ class CustomerPasswordUpdateForm extends BaseForm $data = $context->getRoot()->getData(); if ($data["password"] != $data["password_confirm"]) { - $context->addViolation("password confirmation is not the same as password field."); + $context->addViolation("Password confirmation is not the same as password field."); } }