Merge branch 'frontend' of github.com:thelia/thelia into frontend

This commit is contained in:
badsuricate
2013-10-14 14:36:17 +02:00
9 changed files with 103 additions and 61 deletions

View File

@@ -9,24 +9,36 @@
<default key="_view">index</default>
</route>
<!-- Search routes -->
<route id="search" path="/search">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">search</default>
</route>
<!-- Customer routes -->
<!-- Customer routes : Register -->
<route id="customer.create.process" path="/register" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
<default key="_view">register</default>
</route>
<route id="customer.create.view" path="/register">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">register</default>
</route>
<!-- Customer routes : Login -->
<route id="customer.login.process" path="/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">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">login</default>
</route>
<!-- Customer routes : Logout -->
<route id="customer.logout.process" path="/logout">
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
</route>
@@ -36,21 +48,11 @@
<default key="_view">account</default>
</route>
<route id="customer.create.process" path="/customer/create" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
<default key="_view">register</default>
</route>
<route id="customer.update.process" path="/customer/update" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::updateAction</default>
</route>
<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.password.retrieve.view" path="/password" methods="get">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>

View File

@@ -193,31 +193,34 @@ class CustomerController extends BaseFrontController
$form = $this->validateForm($customerLoginForm, "post");
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
try {
$customer = $authenticator->getAuthentifiedUser();
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
$this->processLogin($customer);
$customer = $authenticator->getAuthentifiedUser();
$this->redirectSuccess($customerLoginForm);
$this->processLogin($customer);
$this->redirectSuccess($customerLoginForm);
} catch (UsernameNotFoundException $e) {
$message = "1.Wrong email or password. Please try again";
} catch (WrongPasswordException $e) {
$message = "2.Wrong email or password. Please try again";
} catch (AuthenticationException $e) {
$message = "3.Wrong email or password. Please try again";
}
} 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()));
}
// If User is a new customer
$form = $customerLoginForm->getForm();
if ($form->get('account')->getData() == 0 && !$form->get("email")->getErrors()) {
$this->redirectToRoute("customer.create.view", array("email" => $form->get("email")->getData()));
} else {
$message = sprintf("Please check your input: %s", $e->getMessage());
}
$message = sprintf("Please check your input: %s", $e->getMessage());
} catch (UsernameNotFoundException $e) {
$message = "Wrong email or password. Please try again";
} catch (WrongPasswordException $e) {
$message = "Wrong email or password. Please try again";
} catch (AuthenticationException $e) {
$message = "Wrong email or password. Please try again";
} catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
}

View File

@@ -151,6 +151,11 @@ class Form extends AbstractSmartyPlugin
$template->assign("options", $formFieldView->vars);
/* access to choices */
if (isset($formFieldView->vars['choices'])) {
$template->assign("choices", $formFieldView->vars['choices']);
}
$value = $formFieldView->vars["value"];
/* FIXME: doesnt work. We got "This form should not contain extra fields." error.
// We have a collection

View File

@@ -22,10 +22,18 @@
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
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\Base\CustomerQuery;
/**
* Class CustomerLogin
* @package Thelia\Form
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CustomerLogin extends BaseForm
{
protected function buildForm()
@@ -33,8 +41,14 @@ class CustomerLogin extends BaseForm
$this->formBuilder
->add("email", "email", array(
"constraints" => array(
new NotBlank(),
new Email()
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail")
)
))
),
"label" => Translator::getInstance()->trans("Please enter your email address"),
"label_attr" => array(
@@ -42,18 +56,40 @@ class CustomerLogin extends BaseForm
),
"required" => true
))
->add("account", "choice", array(
"choices" => array(
0 => Translator::getInstance()->trans("No, I am a new customer."),
1 => Translator::getInstance()->trans("Yes, I have a password :")
),
"label_attr" => array(
"for" => "account"
),
"data" => 0
))
->add("password", "password", array(
"constraints" => array(
new NotBlank()
new Constraints\NotBlank()
),
"label" => Translator::getInstance()->trans("Please enter your password"),
"label_attr" => array(
"for" => "password"
),
"required" => true
))
->add("remember_me", "checkbox")
;
'required' => false
));
}
/**
* If the user select "I'am a new customer", we make sure is email address does not exit in the database.
*/
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["account"] == 0) {
$customer = CustomerQuery::create()->findOneByEmail($value);
if ($customer) {
$context->addViolation("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password.");
}
}
}
public function getName()

View File

@@ -1,6 +1,7 @@
/* FONT PATH
* -------------------------- */
/*
@font-face {
font-family: 'FontAwesome';
src: url('@{FontAwesomePath}/fontawesome-webfont.eot?v=@{FontAwesomeVersion}');
@@ -11,4 +12,15 @@
// src: url('@{FontAwesomePath}/FontAwesome.otf') format('opentype'); // used when developing fonts
font-weight: normal;
font-style: normal;
}*/
@font-face {
font-family: 'FontAwesome';
src: url('@{FontAwesomePath}/fontawesome-webfont.eot?v=3');
src: url('@{FontAwesomePath}/fontawesome-webfont.eot?#iefix&v=3') format('embedded-opentype'),
url('@{FontAwesomePath}/fontawesome-webfont.woff?v=3') format('woff'),
url('@{FontAwesomePath}/fontawesome-webfont.ttf?v=3') format('truetype'),
url('@{FontAwesomePath}/fontawesome-webfont.svg?v=3#fontawesomeregular') format('svg');
// src: url('@{FontAwesomePath}/FontAwesome.otf') format('opentype'); // used when developing fonts
font-weight: normal;
font-style: normal;
}

View File

@@ -1,6 +1,5 @@
// Thelia
@import "variables.less";
//@import "path.less";
// Thelia : Layout
@import "global.less";

View File

@@ -1,14 +0,0 @@
/* FONT PATH
* -------------------------- */
@font-face {
font-family: 'FontAwesome';
src: url('@{FontAwesomePath}/fontawesome-webfont.eot');
src: url('@{FontAwesomePath}/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
url('@{FontAwesomePath}/fontawesome-webfont.woff') format('woff'),
url('@{FontAwesomePath}/fontawesome-webfont.ttf') format('truetype'),
url('@{FontAwesomePath}/fontawesome-webfont.svg#fontawesomeregular') format('svg');
// src: url('@{FontAwesomePath}/FontAwesome.otf') format('opentype'); // used when developing fonts
font-weight: normal;
font-style: normal;
}

View File

@@ -41,17 +41,16 @@
{/form_field}
<fieldset>
{form_field form=$form field="account"}
<legend>{intl l="Do you have an account?"}</legend>
<div class="radio radio-account0" >
<label for="account0">
<input type="radio" name="account" id="account0" data-toggle="password" value="0"> {intl l="No, I am a new customer."}
</label>
</div>
<div class="radio radio-account1">
<label for="account1">
<input type="radio" name="account" id="account1" data-toggle="password" value="1" checked> {intl l="Yes, I have a password :"}
</label>
</div>
{foreach $choices as $choice}
<div class="radio radio-account{$choice->value}">
<label for="{$label_attr.for}{$choice->value}">
<input type="radio" name="{$name}" id="{$label_attr.for}{$choice->value}" data-toggle="password" value="{$choice->value}"{if $value === {$choice->value}} checked{/if}> {$choice->label}
</label>
</div>
{/foreach}
{/form_field}
{form_field form=$form field="password"}
<div class="form-group group-password{if $error} has-error{/if}">
<label for="{$label_attr.for}" class="sr-only">{$label}</label>

View File

@@ -15,7 +15,7 @@
<h1 id="main-label" class="page-header">{intl l="Create New Account"}</h1>
{form name="thelia.customer.creation"}
<form id="form-register" class="form-horizontal" action="{url path="/customer/create"}" method="post" role="form">
<form id="form-register" class="form-horizontal" action="{url path="/register"}" method="post" role="form" novalidate>
{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}