Skip to content

Commit

Permalink
Add new method updatePasswordAction (Not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
touffies committed Oct 22, 2013
1 parent 5dc33ae commit a91303a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/lib/Thelia/Config/Resources/routing/front.xml
Expand Up @@ -76,7 +76,7 @@


<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>
</route>

Expand Down
40 changes: 40 additions & 0 deletions core/lib/Thelia/Controller/Front/CustomerController.php
Expand Up @@ -31,6 +31,7 @@
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;
Expand All @@ -49,6 +50,7 @@ class CustomerController extends BaseFrontController
{
use \Thelia\Cart\CartTrait;


public function newPasswordAction()
{
if (! $this->getSecurityContext()->hasCustomerUser()) {
Expand Down Expand Up @@ -158,6 +160,44 @@ public function viewAction()
$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()) {
Expand Down
2 changes: 0 additions & 2 deletions core/lib/Thelia/Form/CustomerLogin.php
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions core/lib/Thelia/Form/CustomerPasswordUpdateForm.php
Expand Up @@ -25,7 +25,6 @@
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator;

/**
Expand Down Expand Up @@ -80,15 +79,15 @@ protected function buildForm()

public function verifyCurrentPasswordField($value, ExecutionContextInterface $context)
{

// Check current password
}

public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$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.");
}
}

Expand Down

0 comments on commit a91303a

Please sign in to comment.