complete login form

This commit is contained in:
Manuel Raynaud
2013-09-10 12:16:19 +02:00
parent 71928ec879
commit 7eb3ec41fe
14 changed files with 101 additions and 32 deletions

View File

@@ -26,6 +26,7 @@
<route id="customer.login.process" path="/customer/login" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
<default key="_view">login</default>
</route>
<route id="customer.login.view" path="/login">

View File

@@ -179,7 +179,14 @@ class BaseController extends ContainerAware
return $form;
}
else {
throw new FormValidationException(sprintf("Missing or invalid data: %s", $this->getErrorMessages($form)));
$errorMessage = null;
if ($form->get("error_message")->getData() != null) {
$errorMessage = $form->get("error_message")->getData();
} else {
$errorMessage = sprintf("Missing or invalid data: %s", $this->getErrorMessages($form));
}
throw new FormValidationException($errorMessage);
}
}
else {

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Symfony\Component\Routing\Router;
use Thelia\Controller\BaseController;
use Thelia\Tools\URL;
@@ -34,8 +35,8 @@ class BaseFrontController extends BaseController
*
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
*/
protected function getRoute($routeId) {
return $this->getRouteFromRouter('router.front', $routeId);
protected function getRoute($routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
return $this->getRouteFromRouter('router.front', $routeId, $parameters, $referenceType);
}
/**
@@ -44,7 +45,7 @@ class BaseFrontController extends BaseController
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
*/
public function redirectToRoute($routeId, $urlParameters = array()) {
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
public function redirectToRoute($routeId, $urlParameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters));
}
}

View File

@@ -39,6 +39,7 @@ use Thelia\Core\Factory\ActionEventFactory;
use Thelia\Tools\URL;
use Thelia\Log\Tlog;
use Thelia\Core\Security\Exception\WrongPasswordException;
use Symfony\Component\Routing\Router;
/**
* Class CustomerController
@@ -167,16 +168,25 @@ class CustomerController extends BaseFrontController
}
catch (FormValidationException $e) {
if ($request->request->has("account")) {
$account = $request->request->get("account");
$form = $customerLoginForm->getForm();
if($account == 0 && $form->get("email")->getData() !== null) {
$this->redirectToRoute("customer.create.view", array("email" => $form->get("email")->getData()));
}
}
$message = sprintf("Please check your input: %s", $e->getMessage());
}
catch(UsernameNotFoundException $e) {
$message = "This customer email was not found.";
$message = "Wrong email or password. Please try again";
}
catch (WrongPasswordException $e) {
$message = "Wrong password. Please try again.";
$message = "Wrong email or password. Please try again";
}
catch(AuthenticationException $e) {
$message = "Sorry, we failed to authentify you. Please try again.";
$message = "Wrong email or password. Please try again";
}
catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());

View File

@@ -20,7 +20,7 @@ class Translator extends BaseTranslator
* Return this class instance, only once instanciated.
*
* @throws \RuntimeException if the class has not been instanciated.
* @return Thelia\Core\Translation\Translator the instance.
* @return \Thelia\Core\Translation\Translator the instance.
*/
public static function getInstance() {
if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized.");

View File

@@ -102,6 +102,10 @@ abstract class BaseForm
$this->formBuilder->add("success_url", "text");
}
if (! $this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "text");
}
$this->form = $this->formBuilder->getForm();
}

View File

@@ -22,24 +22,38 @@
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
class CustomerLogin extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("email", "text", array(
->add("email", "email", array(
"constraints" => array(
new NotBlank(),
new Email()
)
),
"label" => Translator::getInstance()->trans("Please enter your email address"),
"label_attr" => array(
"for" => "email"
),
"required" => true
))
->add("password", "password", array(
"constraints" => array(
new NotBlank()
)
),
"label" => Translator::getInstance()->trans("Please enter your password"),
"label_attr" => array(
"for" => "password"
),
"required" => true
))
->add("remember_me", "checkbox")
;
@@ -49,4 +63,5 @@ class CustomerLogin extends BaseForm
{
return "thelia_customer_login";
}
}

View File

@@ -121,6 +121,11 @@ class URL
$base_url = $this->getBaseUrl();
// TODO fix this ugly patch
if(strpos($path, "index_dev.php")) {
$path = str_replace('index_dev.php', '', $path);
}
// If only a path is requested, be sure to remove the script name (index.php or index_dev.php), if any.
if ($path_only == self::PATH_TO_FILE) {
// As the base_url always ends with '/', if we don't find / at the end, we have a script.