Merge branch 'master' into loops
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,6 +15,5 @@ coverage
|
||||
.project
|
||||
.settings/
|
||||
local/cache/*
|
||||
composer.lock
|
||||
web/assets/*
|
||||
web/.htaccess
|
||||
|
||||
13
.travis.yml
Executable file
13
.travis.yml
Executable file
@@ -0,0 +1,13 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- "5.4"
|
||||
- "5.5"
|
||||
|
||||
env:
|
||||
- DB_USER=root
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-dist --dev
|
||||
- sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi"
|
||||
- php Thelia thelia:install --db_host=localhost --db_username=$DB_USER --db_name=thelia
|
||||
@@ -36,6 +36,7 @@
|
||||
"simplepie/simplepie": "dev-master"
|
||||
},
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"fzaninotto/faker": "dev-master"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
|
||||
1995
composer.lock
generated
Executable file
1995
composer.lock
generated
Executable file
File diff suppressed because it is too large
Load Diff
@@ -134,7 +134,7 @@ class BaseAdminController extends ContainerAware
|
||||
*/
|
||||
public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
|
||||
{
|
||||
return "thelia2/$route";
|
||||
return "thelia2/$route"; //FIXME
|
||||
|
||||
//return $this->container->get('router')->generate($route, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,30 @@ class Install extends ContainerAwareCommand
|
||||
->setName("thelia:install")
|
||||
->setDescription("Install thelia using cli tools. For now Thelia only use mysql database")
|
||||
->setHelp("The <info>thelia:install</info> command install Thelia database and create config file needed.")
|
||||
->addOption(
|
||||
"db_host",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"host for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_username",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"username for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_password",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"password for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_name",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"database name"
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
@@ -56,9 +80,19 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$this->checkPermission($output);
|
||||
|
||||
do {
|
||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||
} while(false === $connection = $this->tryConnection($connectionInfo, $output));
|
||||
|
||||
$connectionInfo = array(
|
||||
"host" => $input->getOption("db_host"),
|
||||
"dbName" => $input->getOption("db_name"),
|
||||
"username" => $input->getOption("db_username"),
|
||||
"password" => $input->getOption("db_password")
|
||||
);
|
||||
|
||||
|
||||
|
||||
while(false === $connection = $this->tryConnection($connectionInfo, $output)) {
|
||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||
}
|
||||
|
||||
$this->createDatabase($connection, $connectionInfo["dbName"]);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Product" name="product"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Feed" name="feed"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Auth" name="auth"/>
|
||||
</loops>
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@
|
||||
|
||||
<!-- Security -->
|
||||
|
||||
<service id="thelia.security" class="Thelia\Core\Security\SecurityManager" />
|
||||
<service id="thelia.security" class="Thelia\Core\Security\SecurityContext" />
|
||||
|
||||
<!-- Parser configuration -->
|
||||
|
||||
@@ -83,6 +84,8 @@
|
||||
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
<argument type="service" id="thelia.security"/>
|
||||
|
||||
<call method="setLoopList">
|
||||
<argument>%thelia.parser.loops%</argument>
|
||||
</call>
|
||||
|
||||
35
core/lib/Thelia/Core/Security/AuthenticationProcessor.php
Executable file
35
core/lib/Thelia/Core/Security/AuthenticationProcessor.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\Security\Authentication\UsernamePasswordAuthenticator;
|
||||
use Thelia\Core\Security\User\UserProvider\CustomerUserProvider;
|
||||
use Thelia\Core\Security\Encoder\PasswordHashEncoder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class AuthenticationProcessor {
|
||||
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function createToken(Request $request) {
|
||||
|
||||
$context = $request->get('_context');
|
||||
|
||||
try {
|
||||
$securityContext = $this->container->get("security.$context");
|
||||
|
||||
$token = new UsernamePasswordToken(
|
||||
$request->get('_username'),
|
||||
$request->get('_password')
|
||||
);
|
||||
|
||||
$securityContext->setToken($token);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
@@ -18,32 +17,42 @@
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Core\Security\Encoder;
|
||||
|
||||
namespace Thelia\Tests\Security;
|
||||
|
||||
use Thelia\Core\Security\SecurityManager;
|
||||
/**
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
* use password api include in php 5.5 and available throw the password_compat library.
|
||||
*
|
||||
* Class PasswordPhpCompatEncoder
|
||||
* @package Thelia\Core\Security\Encoder
|
||||
*/
|
||||
class SecurityManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetSetToken()
|
||||
{
|
||||
/*
|
||||
$context = new SecurityManager($authProvider)(
|
||||
$this->getMock('AuthenticationProviderInterface'),
|
||||
$this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
|
||||
);
|
||||
$this->assertNull($context->getToken());
|
||||
class PasswordPhpCompatEncoder implements PasswordEncoderInterface {
|
||||
|
||||
$context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
|
||||
$this->assertSame($token, $context->getToken());
|
||||
*/
|
||||
// $this->assertFalse(1==1, "faux !");
|
||||
/**
|
||||
* Encode a string.
|
||||
*
|
||||
* @param string $password the password to encode
|
||||
* @param string $algorithm the hash() algorithm
|
||||
* @return string $salt the salt, the salt is not used here.
|
||||
*/
|
||||
public function encode($password, $algorithm, $salt = null)
|
||||
{
|
||||
return password_hash($password, $algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a string against an encoded password.
|
||||
*
|
||||
* @param string $string the string to compare against password
|
||||
* @param string $password the encoded password
|
||||
* @param string $algorithm the hash() algorithm, not used here
|
||||
* @return string $salt the salt, not used here
|
||||
*/
|
||||
public function isEqual($string, $password, $algorithm = null, $salt = null)
|
||||
{
|
||||
return password_verify($string, $password);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class SecurityManager {
|
||||
class SecurityContext {
|
||||
/*
|
||||
protected $authProvider;
|
||||
|
||||
@@ -21,12 +21,12 @@ class UsernamePasswordToken extends AbstractToken
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($username, $password, $authenticated = false)
|
||||
public function __construct($username, $password, array $roles = array())
|
||||
{
|
||||
$this->setUser($username);
|
||||
$this->credentials = $password;
|
||||
|
||||
parent::setAuthenticated($authenticated);
|
||||
parent::setAuthenticated(count($roles) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\User\UserProviderInterface;
|
||||
use Thelia\Model\Admin;
|
||||
use Thelia\Core\Security\Encoder\PasswordEncoderInterface;
|
||||
namespace Thelia\Core\Security\User\UserProvider;
|
||||
|
||||
class AdminUserProvider implements UserProviderInterface {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\User\UserProviderInterface;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Core\Security\UserNotFoundException;
|
||||
use Thelia\Core\Security\Encoder\PasswordEncoderInterface;
|
||||
namespace Thelia\Core\Security\User\UserProvider;
|
||||
|
||||
|
||||
class CustomerUserProvider implements UserProviderInterface {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Security\User;
|
||||
namespace Thelia\Core\Security\User\UserProvider;
|
||||
|
||||
interface UserProviderInterface {
|
||||
/**
|
||||
@@ -27,11 +27,12 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class BaseLoop
|
||||
* @package Thelia\Tpex\Element\Loop
|
||||
* @package TThelia\Core\Template\Element
|
||||
*/
|
||||
abstract class BaseLoop
|
||||
{
|
||||
@@ -44,19 +45,53 @@ abstract class BaseLoop
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
/**
|
||||
* @var Thelia\Core\Security\SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
|
||||
private $args;
|
||||
|
||||
protected function getDefaultArgs()
|
||||
/**
|
||||
* Create a new Loop
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
* @param Thelia\Core\Security\SecurityContext $securityContext
|
||||
*/
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher, SecurityContext $securityContext)
|
||||
{
|
||||
return array(
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', 10),
|
||||
);
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->securityContext = $securityContext;
|
||||
|
||||
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Define common loop arguments
|
||||
*
|
||||
* @return an array ofL \Thelia\Core\Template\Loop\Argument\Argument
|
||||
*/
|
||||
protected function getDefaultArgs()
|
||||
{
|
||||
return array(
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', 10),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a getter to loop parameters
|
||||
*
|
||||
* @param string $name the methode name (only getArgname is supported)
|
||||
* @param mixed $arguments this parameter is ignored
|
||||
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
|
||||
*/
|
||||
public function __call($name, $arguments) {
|
||||
|
||||
if (substr($name, 0, 3) == 'get') {
|
||||
|
||||
$argName = strtolower(substr($name, 3));
|
||||
@@ -65,22 +100,6 @@ abstract class BaseLoop
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf("Unsupported magic method %s. only getArgname() is supported.", $name));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Loop
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
|
||||
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,30 +123,28 @@ abstract class BaseLoop
|
||||
if($value === null && $argument->mandatory) {
|
||||
$faultActor[] = $argument->name;
|
||||
$faultDetails[] = sprintf('"%s" parameter is missing', $argument->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check if empty */
|
||||
if($value === '' && !$argument->empty) {
|
||||
else if($value === '' && !$argument->empty) {
|
||||
/* check if empty */
|
||||
$faultActor[] = $argument->name;
|
||||
$faultDetails[] = sprintf('"%s" parameter cannot be empty', $argument->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check type */
|
||||
if($value !== null && !$argument->type->isValid($value)) {
|
||||
else if($value !== null && !$argument->type->isValid($value)) {
|
||||
/* check type */
|
||||
$faultActor[] = $argument->name;
|
||||
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
/* set default */
|
||||
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
|
||||
if($value === null) {
|
||||
$value = $argument->default;
|
||||
}
|
||||
|
||||
/* set default */
|
||||
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
|
||||
if($value === null) {
|
||||
$value = $argument->default;
|
||||
}
|
||||
$argument->setValue($value);
|
||||
}
|
||||
|
||||
$argument->setValue($value);
|
||||
$this->args->next();
|
||||
}
|
||||
|
||||
if (!empty($faultActor)) {
|
||||
|
||||
92
core/lib/Thelia/Core/Template/Loop/Auth.php
Executable file
92
core/lib/Thelia/Core/Template/Loop/Auth.php
Executable file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Auth extends BaseLoop
|
||||
{
|
||||
public function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createAnyTypeArgument('roles', null, true),
|
||||
Argument::createAnyTypeArgument('permissions')
|
||||
);
|
||||
}
|
||||
|
||||
private function _explode($commaSeparatedValues)
|
||||
{
|
||||
|
||||
$array = explode(',', $commaSeparatedValues);
|
||||
|
||||
if (array_walk($array, function(&$item) {
|
||||
$item = strtoupper(trim($item));
|
||||
})) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$roles = $this->_explode($this->getRoles());
|
||||
$permissions = $this->_explode($this->getPermissions());
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
try {
|
||||
$this->securityContext->isGranted($roles, $permissions == null ? array() : $permissions);
|
||||
|
||||
// Create an empty row: loop is no longer empty :)
|
||||
$loopResult->addRow(new LoopResultRow());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Not granted, loop is empty
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -26,15 +26,15 @@ namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
|
||||
use Thelia\Core\Security\SecurityManager;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
|
||||
class Security implements SmartyPluginInterface
|
||||
{
|
||||
private $securityManager;
|
||||
private $securityContext;
|
||||
|
||||
public function __construct(SecurityManager $securityManager)
|
||||
public function __construct(SecurityContext $securityContext)
|
||||
{
|
||||
$this->securityManager = $securityManager;
|
||||
$this->securityContext = $securityContext;
|
||||
}
|
||||
|
||||
private function _explode($commaSeparatedValues)
|
||||
@@ -54,17 +54,16 @@ class Security implements SmartyPluginInterface
|
||||
/**
|
||||
* Process security check function
|
||||
*
|
||||
* @param unknown $params
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string
|
||||
* @return string no text is returned.
|
||||
*/
|
||||
public function checkAUth($params, &$smarty)
|
||||
public function checkAuthFunction($params, &$smarty)
|
||||
{
|
||||
$roles = $this->_explode($params['role']);
|
||||
$permissions = $this->_explode($params['role']);
|
||||
|
||||
$this->securityManager->isGranted($roles, $permissions);
|
||||
$permissions = $this->_explode($params['permissions']);
|
||||
|
||||
$this->securityContext->isGranted($roles, $permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +74,7 @@ class Security implements SmartyPluginInterface
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAUth'),
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ use Thelia\Core\Template\Element\Exception\InvalidElementException;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
|
||||
class TheliaLoop implements SmartyPluginInterface
|
||||
{
|
||||
@@ -40,16 +41,17 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
protected $loopDefinition = array();
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $dispatcher;
|
||||
protected $securityContext;
|
||||
|
||||
protected $loopstack = array();
|
||||
protected $varstack = array();
|
||||
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher)
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher, SecurityContext $securityContext)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->securityContext = $securityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +296,8 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
|
||||
$loop = $class->newInstance(
|
||||
$this->request,
|
||||
$this->dispatcher
|
||||
$this->dispatcher,
|
||||
$this->securityContext
|
||||
);
|
||||
|
||||
$loop->initializeArgs($smartyParams);
|
||||
|
||||
@@ -22,10 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContext;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
@@ -36,6 +36,6 @@ class Admin extends BaseAdmin implements UserInterface
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRoles() {
|
||||
return array(new Role('USER_ADMIN'));
|
||||
return array(new Role('ROLE_ADMIN'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
$this->setAlgo("PASSWORD_BCRYPT");
|
||||
return parent::setPassword(password_hash($password, PASSWORD_BCRYPT));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
@@ -132,6 +132,6 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRoles() {
|
||||
return array(new Role('USER_CUSTOMER'));
|
||||
return array(new Role('ROLE_CUSTOMER'));
|
||||
}
|
||||
}
|
||||
|
||||
31
core/lib/Thelia/Tests/Core/Security/Encoder/PasswordPhpCompatEncoderTest.php
Executable file
31
core/lib/Thelia/Tests/Core/Security/Encoder/PasswordPhpCompatEncoderTest.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: manu
|
||||
* Date: 09/07/13
|
||||
* Time: 10:02
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
namespace Thelia\Tests\Security\Encoder;
|
||||
|
||||
|
||||
use Thelia\Core\Security\Encoder\PasswordPhpCompatEncoder;
|
||||
|
||||
class PasswordPhpCompatEncoderTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $encoder;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->encoder = new PasswordPhpCompatEncoder();
|
||||
}
|
||||
|
||||
public function testEncode()
|
||||
{
|
||||
$hash = $this->encoder->encode("foo", PASSWORD_BCRYPT);
|
||||
|
||||
$this->assertEquals($hash, crypt("foo", $hash));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\Token\UsernamePasswordToken;
|
||||
|
||||
class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$token = new UsernamePasswordToken('username', 'password');
|
||||
|
||||
$this->assertFalse($token->isAuthenticated());
|
||||
|
||||
$token = new UsernamePasswordToken('username', 'password', true);
|
||||
$this->assertTrue($token->isAuthenticated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testSetAuthenticatedToTrue()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->setAuthenticated(true);
|
||||
}
|
||||
|
||||
public function testSetAuthenticatedToFalse()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->setAuthenticated(false);
|
||||
$this->assertFalse($token->isAuthenticated());
|
||||
}
|
||||
|
||||
public function testEraseCredentials()
|
||||
{
|
||||
$token = new UsernamePasswordToken('foo', 'bar', true);
|
||||
$token->eraseCredentials();
|
||||
$this->assertEquals('', $token->getCredentials());
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $logger;
|
||||
|
||||
protected $regex = "/(\\d)(:)(\\s+)(%s)(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)((?:2|1)\\d{3}(?:-|\\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))(.)(\\s+)(%s)([\n])/is";
|
||||
//protected $regex = "/(\\d)(:)(\\s+)(%s)(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)(\\d{4})(-)(\\d{2})(-)(\\d{2})(\\s+)(\\d{2})(:)(\\d{2})(:)(\\d{2})(:)(\\s+)(%s)([\n])/is";
|
||||
protected $regex = "/[0-9]+:[\s](%s)+[\s]\[[a-zA-Z\.]+:[a-zA-Z]+\(\)\][\s]\{[0-9]+\}[\s][0-9]{4}-[0-9]{2}-[0-9]{2}[\s][0-9]{2}:[0-9]{2}:[0-9]{2}:[\s](%s).*$/is";
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
{include file="includes/header.html"}
|
||||
<div>
|
||||
|
||||
{loop type="auth" name="auth_test" roles="CUSTOMER"}
|
||||
<p>Customer is authentified :-)</p>
|
||||
{/loop}
|
||||
|
||||
{elseloop rel="auth_test"}
|
||||
<p>Customer is not authentified :-(</p>
|
||||
{/elseloop}
|
||||
|
||||
An image from asset directory :
|
||||
{images file='assets/img/logo-thelia-34px.png'}<img src="{$asset_url}" alt="{intl l='Thelia, solution e-commerce libre'}" />{/images}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user