Add new method updatePasswordAction (Not finished)

This commit is contained in:
touffies
2013-10-23 00:07:27 +02:00
parent 5dc33aec4d
commit a91303a27d
4 changed files with 43 additions and 6 deletions

View File

@@ -76,7 +76,7 @@
<route id="customer.password.change.process" path="/account/password" methods="post"> <route id="customer.password.change.process" path="/account/password" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::newPasswordAction</default> <default key="_controller">Thelia\Controller\Front\CustomerController::updatePasswordAction</default>
<default key="_view">account-password</default> <default key="_view">account-password</default>
</route> </route>

View File

@@ -31,6 +31,7 @@ use Thelia\Core\Security\Exception\UsernameNotFoundException;
use Thelia\Form\CustomerCreateForm; use Thelia\Form\CustomerCreateForm;
use Thelia\Form\CustomerLogin; use Thelia\Form\CustomerLogin;
use Thelia\Form\CustomerLostPasswordForm; use Thelia\Form\CustomerLostPasswordForm;
use Thelia\Form\CustomerPasswordUpdateForm;
use Thelia\Form\CustomerUpdateForm; use Thelia\Form\CustomerUpdateForm;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\Customer; use Thelia\Model\Customer;
@@ -49,6 +50,7 @@ class CustomerController extends BaseFrontController
{ {
use \Thelia\Cart\CartTrait; use \Thelia\Cart\CartTrait;
public function newPasswordAction() public function newPasswordAction()
{ {
if (! $this->getSecurityContext()->hasCustomerUser()) { if (! $this->getSecurityContext()->hasCustomerUser()) {
@@ -158,6 +160,44 @@ class CustomerController extends BaseFrontController
$this->getParserContext()->addForm($customerUpdateForm); $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() public function updateAction()
{ {
if ($this->getSecurityContext()->hasCustomerUser()) { if ($this->getSecurityContext()->hasCustomerUser()) {

View File

@@ -22,8 +22,6 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Form; namespace Thelia\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\Email;

View File

@@ -25,7 +25,6 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface; use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator; use Thelia\Core\Translation\Translator;
/** /**
@@ -80,7 +79,7 @@ class CustomerPasswordUpdateForm extends BaseForm
public function verifyCurrentPasswordField($value, ExecutionContextInterface $context) public function verifyCurrentPasswordField($value, ExecutionContextInterface $context)
{ {
// Check current password
} }
public function verifyPasswordField($value, ExecutionContextInterface $context) public function verifyPasswordField($value, ExecutionContextInterface $context)
@@ -88,7 +87,7 @@ class CustomerPasswordUpdateForm extends BaseForm
$data = $context->getRoot()->getData(); $data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) { 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.");
} }
} }