Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By Manuel Raynaud (9) and Etienne Roudeix (1)
# Via Manuel Raynaud
* 'master' of https://github.com/thelia/thelia:
  update customer loop in template customer
  strat regiter page
  complete login form
  change link for homepage
  start creating register and login pages
  display good currency in template
  defin currency at runtime
  creating index page
  fix tests
  start integration default template
This commit is contained in:
gmorel
2013-09-10 15:41:59 +02:00
192 changed files with 17914 additions and 225 deletions

View File

@@ -15,17 +15,29 @@
<default key="_view">connexion</default>
</route>
<route id="customer.create.view" path="/register">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</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.login.view" path="/login">
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
<default key="_view">login</default>
</route>
<route id="customer.logout.process" path="/customer/logout">
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
</route>
<!-- end customer routes -->
<!-- customer address routes -->

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

@@ -28,6 +28,7 @@ use Thelia\Core\Security\User\UserInterface;
use Thelia\Exception\InvalidCartException;
use Thelia\Model\CartQuery;
use Thelia\Model\Cart;
use Thelia\Model\Currency;
use Thelia\Tools\URL;
use Thelia\Model\Lang;
@@ -44,9 +45,9 @@ class Session extends BaseSession
/**
* @return \Thelia\Model\Lang|null
*/
public function getLang()
public function getLang($forceDefault = true)
{
return $this->get("thelia.current.lang", Lang::getDefaultLanguage());
return $this->get("thelia.current.lang", $forceDefault ? Lang::getDefaultLanguage():null);
}
public function setLang(Lang $lang)
@@ -68,6 +69,16 @@ class Session extends BaseSession
return $this;
}
public function setCurrency(Currency $currency)
{
$this->set("thelia.current.currency", $currency);
}
public function getCurrency($forceDefault = true)
{
return $this->get("thelia.current.currency", $forceDefault ? Currency::getDefaultCurrency():null);
}
// -- Customer user --------------------------------------------------------
public function setCustomerUser(UserInterface $user)

View File

@@ -59,11 +59,12 @@ abstract class BaseI18nLoop extends BaseLoop
* @param array $columns the i18n columns
* @param string $foreignTable the specified table (default to criteria table)
* @param string $foreignKey the foreign key in this table (default to criteria table)
* @param bool $forceReturn
*
* @return mixed the locale
*/
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) {
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false)
{
/* manage translations */
return ModelCriteriaTools::getI18n(
$this->getBackend_context(),

View File

@@ -31,6 +31,7 @@ use Thelia\Core\Template\ParserContext;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\FolderQuery;
use Thelia\Model\Product;
use Thelia\Model\ProductQuery;
@@ -132,6 +133,35 @@ class DataAccessFunctions extends AbstractSmartyPlugin
}
}
/**
* currency global data
*
* @param $params
* @param $smarty
*/
public function currencyDataAccess($params, $smarty)
{
$currency = $this->request->getSession()->getCurrency();
if ($currency) {
$currencyQuery = CurrencyQuery::create()
->filterById($currency->getId());
return $this->dataAccessWithI18n("Currency", $params, $currencyQuery, array("NAME"));
}
}
/**
* Lang global data
*
* @param $params
* @param $smarty
*/
public function langDataAccess($params, $smarty)
{
return $this->dataAccess("Lang", $params, $this->request->getSession()->getLang());
}
/**
* @param $objectLabel
* @param $params
@@ -231,6 +261,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin
new SmartyPluginDescriptor('function', 'category', $this, 'categoryDataAccess'),
new SmartyPluginDescriptor('function', 'content', $this, 'contentDataAccess'),
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
);
}
}

View File

@@ -135,9 +135,26 @@ class TheliaHttpKernel extends HttpKernel
if ($lang) {
$request->getSession()
->setLang($lang)
->setLocale($lang->getLocale())
;
}
$request->getSession()->setCurrency($this->defineCurrency($request));
}
protected function defineCurrency(Request $request)
{
$currency = null;
if ($request->query->has("currency")) {
$currency = Model\CurrencyQuery::create()->findOneByCode($request->query->get("currency"));
} else {
$currency = $request->getSession()->getCurrency(false);
}
if(null === $currency) {
$currency = Model\Currency::getDefaultCurrency();
}
return $currency;
}
/**
@@ -153,7 +170,7 @@ class TheliaHttpKernel extends HttpKernel
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
if (is_null($lang)) {
return;
return Model\Lang::getDefaultLanguage();
}
//if each lang had is own domain, we redirect the user to the good one.
@@ -175,7 +192,7 @@ class TheliaHttpKernel extends HttpKernel
}
//check if lang is not defined. If not we have to search the good one.
if (null === $request->getSession()->getLang()) {
if (null === $request->getSession()->getLang(false)) {
if (Model\ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
//find lang with domain
@@ -183,7 +200,7 @@ class TheliaHttpKernel extends HttpKernel
}
//find default lang
return Model\LangQuery::create()->findOneByByDefault(1);
return Model\Lang::getDefaultLanguage();
}
}

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

@@ -13,6 +13,17 @@ class Currency extends BaseCurrency {
use \Thelia\Model\Tools\PositionManagementTrait;
public static function getDefaultCurrency()
{
$currency = CurrencyQuery::create()->findOneByByDefault(1);
if (null === $currency) {
throw new \RuntimeException("No default currency is defined. Please define one.");
}
return $currency;
}
/**
* {@inheritDoc}
*/

View File

@@ -23,6 +23,7 @@
namespace Thelia\Tests\Core\Template\Element;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
@@ -34,11 +35,9 @@ use Thelia\Core\HttpFoundation\Session\Session;
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
abstract class BaseLoopTestor extends \Thelia\Tests\TestCaseWithURLToolSetup
abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
{
protected $request;
protected $dispatcher;
protected $securityContext;
protected $container;
protected $instance;
@@ -57,12 +56,35 @@ abstract class BaseLoopTestor extends \Thelia\Tests\TestCaseWithURLToolSetup
public function setUp()
{
$this->request = new Request();
$this->container = new ContainerBuilder();
$session = new Session(new MockArraySessionStorage());
$request = new Request();
$request->setSession($session);
/*$stubEventdispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$stubSecurityContext = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext')
->disableOriginalConstructor()
->getMock();*/
/*$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));*/
/*$this->request = new Request();
$this->request->setSession(new Session(new MockArraySessionStorage()));
$this->dispatcher = new EventDispatcher();
$this->securityContext = new SecurityContext($this->request);
$this->securityContext = new SecurityContext($this->request);*/
$this->container->set('request', $request);
$this->container->set('event_dispatcher', new EventDispatcher());
$this->container->set('thelia.securityContext', new SecurityContext($request));
$this->instance = $this->getTestedInstance();
$this->instance->initializeArgs($this->getMandatoryArguments());

View File

@@ -41,7 +41,7 @@ class AccessoryTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Accessory($this->request, $this->dispatcher, $this->securityContext);
return new Accessory($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class AddressTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Address($this->request, $this->dispatcher, $this->securityContext);
return new Address($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class AssociatedContentTest extends BaseLoopTestor
public function getTestedInstance()
{
return new AssociatedContent($this->request, $this->dispatcher, $this->securityContext);
return new AssociatedContent($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class AttributeAvailabilityTest extends BaseLoopTestor
public function getTestedInstance()
{
return new AttributeAvailability($this->request, $this->dispatcher, $this->securityContext);
return new AttributeAvailability($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class AttributeCombinationTest extends BaseLoopTestor
public function getTestedInstance()
{
return new AttributeCombination($this->request, $this->dispatcher, $this->securityContext);
return new AttributeCombination($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class AttributeTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Attribute($this->request, $this->dispatcher, $this->securityContext);
return new Attribute($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class CategoryTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Category($this->request, $this->dispatcher, $this->securityContext);
return new Category($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class ContentTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Content($this->request, $this->dispatcher, $this->securityContext);
return new Content($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class CountryTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Country($this->request, $this->dispatcher, $this->securityContext);
return new Country($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class CurrencyTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Currency($this->request, $this->dispatcher, $this->securityContext);
return new Currency($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class CustomerTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Customer($this->request, $this->dispatcher, $this->securityContext);
return new Customer($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class FeatureAvailabilityTest extends BaseLoopTestor
public function getTestedInstance()
{
return new FeatureAvailability($this->request, $this->dispatcher, $this->securityContext);
return new FeatureAvailability($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class FeatureTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Feature($this->request, $this->dispatcher, $this->securityContext);
return new Feature($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class FeatureValueTest extends BaseLoopTestor
public function getTestedInstance()
{
return new FeatureValue($this->request, $this->dispatcher, $this->securityContext);
return new FeatureValue($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class FolderTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Folder($this->request, $this->dispatcher, $this->securityContext);
return new Folder($this->container);
}
public function getMandatoryArguments()

View File

@@ -41,7 +41,7 @@ class ProductSaleElementsTest extends BaseLoopTestor
public function getTestedInstance()
{
return new ProductSaleElements($this->request, $this->dispatcher, $this->securityContext);
return new ProductSaleElements($this->container);
}
public function getMandatoryArguments()

View File

@@ -32,7 +32,7 @@ use Thelia\Core\Template\Loop\Product;
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
/*class ProductTest extends BaseLoopTestor
class ProductTest extends BaseLoopTestor
{
public function getTestedClassName()
{
@@ -41,11 +41,11 @@ use Thelia\Core\Template\Loop\Product;
public function getTestedInstance()
{
return new Product($this->request, $this->dispatcher, $this->securityContext);
return new Product($this->container);
}
public function getMandatoryArguments()
{
return array();
}
}*/
}

View File

@@ -41,7 +41,7 @@ class TitleTest extends BaseLoopTestor
public function getTestedInstance()
{
return new Title($this->request, $this->dispatcher, $this->securityContext);
return new Title($this->container);
}
public function getMandatoryArguments()

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.