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"> <route id="customer.login.process" path="/customer/login" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default> <default key="_controller">Thelia\Controller\Front\CustomerController::loginAction</default>
<default key="_view">login</default>
</route> </route>
<route id="customer.login.view" path="/login"> <route id="customer.login.view" path="/login">

View File

@@ -179,7 +179,14 @@ class BaseController extends ContainerAware
return $form; return $form;
} }
else { 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 { else {

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Controller\Front; namespace Thelia\Controller\Front;
use Symfony\Component\Routing\Router;
use Thelia\Controller\BaseController; use Thelia\Controller\BaseController;
use Thelia\Tools\URL; use Thelia\Tools\URL;
@@ -34,8 +35,8 @@ class BaseFrontController extends BaseController
* *
* @see \Thelia\Controller\BaseController::getRouteFromRouter() * @see \Thelia\Controller\BaseController::getRouteFromRouter()
*/ */
protected function getRoute($routeId) { protected function getRoute($routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
return $this->getRouteFromRouter('router.front', $routeId); 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 $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @param unknown $urlParameters the URL parametrs, as a var/value pair array * @param unknown $urlParameters the URL parametrs, as a var/value pair array
*/ */
public function redirectToRoute($routeId, $urlParameters = array()) { public function redirectToRoute($routeId, $urlParameters = array(), $referenceType = Router::ABSOLUTE_PATH) {
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters)); $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\Tools\URL;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Core\Security\Exception\WrongPasswordException; use Thelia\Core\Security\Exception\WrongPasswordException;
use Symfony\Component\Routing\Router;
/** /**
* Class CustomerController * Class CustomerController
@@ -167,16 +168,25 @@ class CustomerController extends BaseFrontController
} }
catch (FormValidationException $e) { 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()); $message = sprintf("Please check your input: %s", $e->getMessage());
} }
catch(UsernameNotFoundException $e) { catch(UsernameNotFoundException $e) {
$message = "This customer email was not found."; $message = "Wrong email or password. Please try again";
} }
catch (WrongPasswordException $e) { catch (WrongPasswordException $e) {
$message = "Wrong password. Please try again."; $message = "Wrong email or password. Please try again";
} }
catch(AuthenticationException $e) { catch(AuthenticationException $e) {
$message = "Sorry, we failed to authentify you. Please try again."; $message = "Wrong email or password. Please try again";
} }
catch (\Exception $e) { catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage()); $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. * Return this class instance, only once instanciated.
* *
* @throws \RuntimeException if the class has not been 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() { public static function getInstance() {
if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized."); 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"); $this->formBuilder->add("success_url", "text");
} }
if (! $this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "text");
}
$this->form = $this->formBuilder->getForm(); $this->form = $this->formBuilder->getForm();
} }

View File

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

View File

@@ -121,6 +121,11 @@ class URL
$base_url = $this->getBaseUrl(); $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 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) { 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. // As the base_url always ends with '/', if we don't find / at the end, we have a script.

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

View File

@@ -47,7 +47,7 @@
} }
// Login // Login
var $form_login = $('#form-login'); /* var $form_login = $('#form-login');
if($form_login.size() > 0) { if($form_login.size() > 0) {
$form_login.on('change.account', ':radio', function(){ $form_login.on('change.account', ':radio', function(){
if($(this).val() === '0') if($(this).val() === '0')
@@ -55,7 +55,7 @@
else else
$('#password', $form_login).prop('disabled', false); // Enabled $('#password', $form_login).prop('disabled', false); // Enabled
}).find(':radio:checked').trigger('change.account'); }).find(':radio:checked').trigger('change.account');
} }*/
// Forgot Password // Forgot Password
/* /*

View File

@@ -7,13 +7,13 @@
<div class="carousel-wrapper"> <div class="carousel-wrapper">
<div class="carousel-inner"> <div class="carousel-inner">
<figure class="item active"> <figure class="item active">
{images file='assets/img/carousel/1200x390.png'}<img src="{$asset_url}" alt="img1">{/images} {images file='assets/img/carousel/slider1.png'}<img src="{$asset_url}" alt="img1">{/images}
</figure> </figure>
<figure class="item"> <figure class="item">
{images file='assets/img/carousel/1200x390.png'}<img src="{$asset_url}" alt="img2">{/images} {images file='assets/img/carousel/slider2.png'}<img src="{$asset_url}" alt="img2">{/images}
</figure> </figure>
<figure class="item"> <figure class="item">
{images file='assets/img/carousel/1200x390.png'}<img src="{$asset_url}" alt="img3">{/images} {images file='assets/img/carousel/slider3.png'}<img src="{$asset_url}" alt="img3">{/images}
</figure> </figure>
</div> </div>
</div> </div>
@@ -59,7 +59,7 @@
<div class="product-price"> <div class="product-price">
<div class="price-container" itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <div class="price-container" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="currency" content="USD"> <!-- List of currency : The currency used to describe the product price, in three-letter ISO format. --> <meta itemprop="currency" content="{currency attr="code"}"> <!-- List of currency : The currency used to describe the product price, in three-letter ISO format. -->
<link itemprop="availability" href="http://schema.org/InStock" content="In Stock" /> <link itemprop="availability" href="http://schema.org/InStock" content="In Stock" />
<!-- List of availibility : <!-- List of availibility :
out_of_stock : http://schema.org/OutOfStock out_of_stock : http://schema.org/OutOfStock

View File

@@ -15,37 +15,63 @@
<div class="main"> <div class="main">
<article class="col-main" role="main" aria-labelledby="main-label"> <article class="col-main" role="main" aria-labelledby="main-label">
<h1 id="main-label" class="page-header">Login</h1> <h1 id="main-label" class="page-header">{intl l="Login"}</h1>
<form id="form-login" action="" method="post" role="form"> {form name="thelia.customer.login"}
<form id="form-login" action="{url path="/customer/login"}" method="post" role="form" {form_enctype form=$form}>
{if #form_error}<div class="alert alert-danger">#form_error_message</div>{/if}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{navigate to="return_to"}" /> {* the url the user is redirected to on login success *}
{/form_field}
{form_field form=$form field='error_message'}
<input type="hidden" name="{$name}" value="{intl l="missing or invalid data"}" /> {* the url the user is redirected to on login success *}
{/form_field}
{form_hidden_fields form=$form}
<fieldset> <fieldset>
<div class="form-group group-email"> {form_field form=$form field="email"}
<label for="email">Please enter your email address</label> <div class="form-group group-email {if $error}has-error{/if} ">
<input type="email" name="email" id="email" class="form-control" value="" aria-required="true" autofocus required> <label for="{$label_attr.for}">{$label}</label>
</div> <div class="control-input">
<input type="email" name="{$name}" id="{$label_attr.for}" value="{$value}" class="form-control" {$attr} aria-required="true" autofocus required>
{if $error}
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{/if}
</div>
</div>
{/form_field}
<fieldset> <fieldset>
<legend>Do you have an account?</legend> <legend>{intl l="Do you have an account?"}</legend>
<div class="radio radio-account0" > <div class="radio radio-account0" >
<label for="account0"> <label for="account0">
<input type="radio" name="account" id="account0" data-toggle="password" value="0" <?php if(!(isset($_POST['account']) && $_POST['account'] == '1')) { echo ' checked'; }?>> No, I am a new customer. <input type="radio" name="account" id="account0" data-toggle="password" value="0" > {intl l="No, I am a new customer."}
</label> </label>
</div> </div>
<div class="radio radio-account1"> <div class="radio radio-account1">
<label for="account1"> <label for="account1">
<input type="radio" name="account" id="account1" data-toggle="password" value="1"<?php if(isset($_POST['account']) && $_POST['account'] == '1' ) { echo ' checked'; }?>> Yes, I have a password : <input type="radio" name="account" id="account1" data-toggle="password" value="1" checked> {intl l="Yes, I have a password :"}
</label> </label>
</div> </div>
<div class="form-group group-password"> {form_field form=$form field="password"}
<label for="password" class="sr-only">Please enter your password</label> <div class="form-group group-password {if $error}has-error{/if} ">
<input type="password" name="password" id="password" class="form-control" autocomplete="off"> <label for="{$label_attr.for}" class="sr-only">{$label}</label>
<div class="control-input">
<input type="password" name="{$name}" id="{$label_attr.for}" class="form-control" autocomplete="off">
{if $error}
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{/if}
</div>
</div> </div>
{/form_field}
</fieldset> </fieldset>
</fieldset> </fieldset>
<div class="group-btn"> <div class="group-btn">
<a href="password.php" class="forgot-password">Forgot your Password ?</a> <a href="{url path="/customer/password"}" class="forgot-password">{intl l="Forgot your Password ?"}</a>
<button type="submit" class="btn btn-login">Next</button> <button type="submit" class="btn btn-login">{intl l="Next"}</button>
</div> </div>
</form> </form>
{/form}
</article> </article>
</div> </div>
{/block} {/block}