diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index bbbe6462d..785ee8f48 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -99,47 +99,6 @@ class Customer extends BaseAction implements EventSubscriberInterface $this->getFrontSecurityContext()->clear(); } - /** - * Perform user login. On a successful login, the user is redirected to the URL - * found in the success_url form parameter, or / if none was found. - * - * If login is not successfull, the same view is dispolyed again. - * - * @param ActionEvent $event - */ - public function login(ActionEvent $event) - { - $request = $event->getRequest(); - - $customerLoginForm = new CustomerLogin($request); - - $authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm); - - try { - $user = $authenticator->getAuthentifiedUser(); - - $event->customer = $user; - - } 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()); - } - - // 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. - } - public function changePassword(ActionEvent $event) { // TODO @@ -170,8 +129,6 @@ class Customer extends BaseAction implements EventSubscriberInterface return array( "action.createCustomer" => array("create", 128), "action.modifyCustomer" => array("modify", 128), - "action.loginCustomer" => array("login", 128), - "action.logoutCustomer" => array("logout", 128), ); } } diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php index 76d9d54bc..07f9eb4c8 100644 --- a/core/lib/Thelia/Controller/Front/CustomerController.php +++ b/core/lib/Thelia/Controller/Front/CustomerController.php @@ -23,9 +23,15 @@ namespace Thelia\Controller\Front; use Propel\Runtime\Exception\PropelException; +use Symfony\Component\Validator\Exception\ValidatorException; use Thelia\Core\Event\CustomerCreateOrUpdateEvent; +use Thelia\Core\Event\CustomerLoginEvent; +use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator; +use Thelia\Core\Security\Exception\AuthenticationException; +use Thelia\Core\Security\Exception\UsernameNotFoundException; use Thelia\Core\Security\SecurityContext; use Thelia\Form\CustomerCreation; +use Thelia\Form\CustomerLogin; use Thelia\Form\CustomerModification; use Thelia\Form\Exception\FormValidationException; use Thelia\Model\Customer; @@ -79,6 +85,8 @@ class CustomerController extends BaseFrontController $this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent); + $this->processLogin($customerChangeEvent->getCustomer()); + $this->redirectSuccess(); } catch (FormValidationException $e) { @@ -90,20 +98,45 @@ class CustomerController extends BaseFrontController } } + /** + * Perform user login. On a successful login, the user is redirected to the URL + * found in the success_url form parameter, or / if none was found. + * + * If login is not successfull, the same view is dispolyed again. + * + */ public function loginAction() { - $event = $this->dispatchEvent("loginCustomer"); + $request = $this->getRequest(); - $customerEvent = new CustomerEvent($event->getCustomer()); + $customerLoginForm = new CustomerLogin($request); - $this->processLogin($event->getCustomer(), $customerEvent, true); + $authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm); + + try { + $customer = $authenticator->getAuthentifiedUser(); + + $customerLoginEvent = new CustomerLoginEvent($customer); + + $this->processLogin($customer, $customerLoginEvent); + + $this->redirectSuccess(); + } catch (ValidatorException $e) { + + } catch(UsernameNotFoundException $e) { + + } catch(AuthenticationException $e) { + + } catch (\Exception $e) { + + } } - public function processLogin(Customer $customer,$event = null, $sendLogin = false) + public function processLogin(Customer $customer,$event = null) { $this->getSecurityContext(SecurityContext::CONTEXT_FRONT_OFFICE)->setUser($customer); - if($sendLogin) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event); + if($event) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event); } /** diff --git a/core/lib/Thelia/Core/Event/CustomerLoginEvent.php b/core/lib/Thelia/Core/Event/CustomerLoginEvent.php new file mode 100644 index 000000000..cc363790d --- /dev/null +++ b/core/lib/Thelia/Core/Event/CustomerLoginEvent.php @@ -0,0 +1,42 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +use Thelia\Model\Customer; + +class CustomerLoginEvent { + + protected $customer; + + public function __construct(Customer $customer) + { + $this->customer = $customer; + } + + public function getCustomer() + { + return $this->customer; + } +} \ No newline at end of file