create customer login controller

This commit is contained in:
Manuel Raynaud
2013-08-16 14:24:00 +02:00
parent 4f31627301
commit 0397f5fdf8
3 changed files with 80 additions and 48 deletions

View File

@@ -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),
);
}
}