Merge branch 'admin' into loops
Conflicts: core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php templates/smarty-sample/category.html
This commit is contained in:
@@ -25,13 +25,30 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\CustomerCreation;
|
||||
|
||||
class Customer implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
public function create(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
$customerForm = new CustomerCreation($request);
|
||||
|
||||
$form = $customerForm->getForm();
|
||||
|
||||
|
||||
if ($request->isMethod("post")) {
|
||||
$form->bind($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
echo "ok"; exit;
|
||||
} else {
|
||||
echo "ko"; exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function modify(ActionEvent $event)
|
||||
|
||||
@@ -28,17 +28,23 @@ use Thelia\Form\AdminLogin;
|
||||
|
||||
class AdminController extends BaseAdminController {
|
||||
|
||||
public function indexAction()
|
||||
public function loginAction()
|
||||
{
|
||||
|
||||
$form = $this->getLoginForm();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
if($request->isMethod("POST")) {
|
||||
|
||||
$form->bind($request);
|
||||
|
||||
if($form->isValid()) {
|
||||
if ($form->isValid()) {
|
||||
|
||||
$this->container->get('request')->authenticate(
|
||||
$form->get('username')->getData(),
|
||||
$form->get('password')->getData()
|
||||
);
|
||||
|
||||
echo "valid"; exit;
|
||||
}
|
||||
}
|
||||
@@ -48,13 +54,20 @@ class AdminController extends BaseAdminController {
|
||||
));
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$form = $this->getLoginForm();
|
||||
|
||||
return $this->render("login.html", array(
|
||||
"form" => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
protected function getLoginForm()
|
||||
{
|
||||
$form = $this->getFormBuilder();
|
||||
$adminLogin = new AdminLogin($this->getRequest());
|
||||
|
||||
$adminLogin = new AdminLogin();
|
||||
|
||||
return $adminLogin->buildForm($form, array())->getForm();
|
||||
return $adminLogin->getForm();
|
||||
}
|
||||
|
||||
public function lostAction()
|
||||
|
||||
@@ -48,7 +48,7 @@ class BaseAdminController extends ContainerAware
|
||||
*/
|
||||
public function render($templateName, $args = array())
|
||||
{
|
||||
$args = array_merge($args, array('lang' => 'fr'));
|
||||
$args = array_merge($args, array('lang' => 'fr')); // FIXME
|
||||
|
||||
$response = new Response();
|
||||
|
||||
@@ -57,7 +57,7 @@ class BaseAdminController extends ContainerAware
|
||||
|
||||
public function renderRaw($templateName, $args = array())
|
||||
{
|
||||
$args = array_merge($args, array('lang' => 'fr'));
|
||||
$args = array_merge($args, array('lang' => 'fr')); // FIXME
|
||||
|
||||
return $this->getParser()->render($templateName, $args);
|
||||
}
|
||||
@@ -90,5 +90,6 @@ class BaseAdminController extends ContainerAware
|
||||
return $this->getFormFactory()->createBuilder("form");
|
||||
}
|
||||
|
||||
|
||||
protected function isGranted() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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\Security\Authentication;
|
||||
|
||||
use Thelia\Core\Security\UserNotFoundException;
|
||||
use Thelia\Core\Security\IncorrectPasswordException;
|
||||
|
||||
/**
|
||||
* Aunthentication providers are in charge or retrieving users, and check their
|
||||
* credentials.
|
||||
*
|
||||
* @author Franck
|
||||
*
|
||||
*/
|
||||
interface AuthenticationProviderInterface {
|
||||
|
||||
/**
|
||||
* Set the authentication token
|
||||
*
|
||||
* @param TokenInterface $token the authentication token
|
||||
*/
|
||||
public function setToken(TokenInterface $token);
|
||||
|
||||
|
||||
/**
|
||||
* Set the authentication token
|
||||
*
|
||||
* @param unknown $key
|
||||
*/
|
||||
public function supportsToken(TokenInterface $token);
|
||||
|
||||
/**
|
||||
* Authenticate the token
|
||||
*
|
||||
*@throws Exception if authentication was not successful
|
||||
*/
|
||||
public function authenticate();
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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\Security\Authentication;
|
||||
|
||||
use Thelia\Core\Security\Authentication\AuthenticationProviderInterface;
|
||||
use Thelia\Core\Security\Encoder\PasswordEncoderInterface;
|
||||
use Thelia\Core\Security\User\UserProviderInterface;
|
||||
use Thelia\Security\Token\TokenInterface;
|
||||
use Thelia\Core\Security\Exception\IncorrectPasswordException;
|
||||
use Thelia\Core\Security\Token\UsernamePasswordToken;
|
||||
|
||||
class UsernamePasswordAuthenticator implements AuthenticationProviderInterface {
|
||||
|
||||
protected $userProvider;
|
||||
protected $encoder;
|
||||
|
||||
private $token;
|
||||
|
||||
public function __construct(UserProviderInterface $userProvider, PasswordEncoderInterface $encoder) {
|
||||
$this->userProvider = $userProvider;
|
||||
$this->encoder = $encoder;
|
||||
}
|
||||
|
||||
public function supportsToken(TokenInterface $token) {
|
||||
|
||||
return $token instanceof UsernamePasswordToken;
|
||||
}
|
||||
|
||||
public function authenticate($token) {
|
||||
|
||||
if (!$this->supports($token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Retreive user
|
||||
$user = $this->userProvider->getUser($this->token->getUsername());
|
||||
|
||||
// Check password
|
||||
$authOk = $this->encoder->isEqual($password, $user->getPassword(), $user->getAlgo(), $user->getSalt()) === true;
|
||||
|
||||
$authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $authOk);
|
||||
|
||||
return $authenticatedToken;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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\Security\Encoder;
|
||||
|
||||
/**
|
||||
* This interface defines a password encoder.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
interface PasswordEncoderInterface {
|
||||
|
||||
/**
|
||||
* Encode a string.
|
||||
*
|
||||
* @param string $password the password to encode
|
||||
* @param string $algorithm the hash() algorithm
|
||||
* @return string $salt the salt
|
||||
*/
|
||||
public function encode($password, $algorithm, $salt);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return string $salt the salt
|
||||
*/
|
||||
public function isEqual($string, $password, $algorithm, $salt);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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\Security\Encoder;
|
||||
|
||||
/**
|
||||
* This interface defines a hash based password encoder.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
|
||||
class PasswordHashEncoder implements PasswordEncoderInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($password, $algorithm, $salt)
|
||||
{
|
||||
if (!in_array($algorithm, hash_algos(), true)) {
|
||||
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $algorithm));
|
||||
}
|
||||
|
||||
// Salt the string
|
||||
$salted = $password.$salt;
|
||||
|
||||
// Create the hash
|
||||
$digest = hash($algorithm, $salted, true);
|
||||
|
||||
// "stretch" hash
|
||||
for ($i = 1; $i < 5000; $i++) {
|
||||
$digest = hash($algorithm, $digest.$salted, true);
|
||||
}
|
||||
|
||||
return base64_encode($digest);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEqual($string, $password, $algorithm, $salt)
|
||||
{
|
||||
$encoded = $this->encode($password, $algorithm, $salt);
|
||||
|
||||
return $encoded == $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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\Security\Exception;
|
||||
|
||||
class AuthenticationTokenNotFoundException extends \Exception
|
||||
{
|
||||
}
|
||||
81
core/lib/Thelia/Core/Security/Security/SecurityManager.php
Normal file
81
core/lib/Thelia/Core/Security/Security/SecurityManager.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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\Security;
|
||||
|
||||
use Thelia\Core\Security\Authentication\AuthenticationProviderInterface;
|
||||
use Thelia\Core\Security\Exception\AuthenticationTokenNotFoundException;
|
||||
|
||||
/**
|
||||
* A simple security manager, in charge of authenticating users using various authentication systems.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class SecurityManager {
|
||||
|
||||
protected $authProvider;
|
||||
|
||||
public function __construct(AuthenticationProviderInterface $authProvider) {
|
||||
$this->authProvider = $authProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current token is authenticated
|
||||
*
|
||||
* @throws AuthenticationCredentialsNotFoundException when the security context has no authentication token.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
final public function isGranted()
|
||||
{
|
||||
if (null === $this->token) {
|
||||
throw new AuthenticationTokenNotFoundException('The security context contains no authentication token.');
|
||||
}
|
||||
|
||||
if (!$this->token->isAuthenticated()) {
|
||||
$this->token = $this->authProvider->authenticate($this->token);
|
||||
}
|
||||
|
||||
return $this->token->isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently authenticated token.
|
||||
*
|
||||
* @return TokenInterface|null A TokenInterface instance or null if no authentication information is available
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the token.
|
||||
*
|
||||
* @param TokenInterface $token A TokenInterface token, or null if no further authentication information should be stored
|
||||
*/
|
||||
public function setToken(TokenInterface $token = null)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
}
|
||||
148
core/lib/Thelia/Core/Security/Security/Token/AbstractToken.php
Normal file
148
core/lib/Thelia/Core/Security/Security/Token/AbstractToken.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace Thelia\Core\Security\Token;
|
||||
|
||||
use Thelia\Core\Security\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Base class for Token instances.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class AbstractToken implements TokenInterface
|
||||
{
|
||||
private $user;
|
||||
private $authenticated;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param RoleInterface[] $roles An array of roles
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authenticated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
if ($this->user instanceof UserInterface) {
|
||||
return $this->user->getUsername();
|
||||
}
|
||||
|
||||
return (string) $this->user;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user in the token.
|
||||
*
|
||||
* The user can be a UserInterface instance, or an object implementing
|
||||
* a __toString method or the username as a regular string.
|
||||
*
|
||||
* @param mixed $user The user
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
if (!($user instanceof UserInterface || is_string($user))) {
|
||||
throw new \InvalidArgumentException('$user must be an instanceof UserInterface, or a primitive string.');
|
||||
}
|
||||
|
||||
if (null === $this->user) {
|
||||
$changed = false;
|
||||
} elseif ($this->user instanceof UserInterface) {
|
||||
if (!$user instanceof UserInterface) {
|
||||
$changed = true;
|
||||
} else {
|
||||
$changed = $this->hasUserChanged($user);
|
||||
}
|
||||
} elseif ($user instanceof UserInterface) {
|
||||
$changed = true;
|
||||
} else {
|
||||
$changed = (string) $this->user !== (string) $user;
|
||||
}
|
||||
|
||||
if ($changed) {
|
||||
$this->setAuthenticated(false);
|
||||
}
|
||||
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
return $this->authenticated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthenticated($authenticated)
|
||||
{
|
||||
$this->authenticated = (Boolean) $authenticated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eraseCredentials()
|
||||
{
|
||||
if ($this->getUser() instanceof UserInterface) {
|
||||
$this->getUser()->eraseCredentials();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array($this->user, $this->authenticated));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list($this->user, $this->authenticated) = unserialize($serialized);
|
||||
}
|
||||
|
||||
private function hasUserChanged(UserInterface $user)
|
||||
{
|
||||
if (!($this->user instanceof UserInterface)) {
|
||||
throw new \BadMethodCallException('Method "hasUserChanged" should be called when current user class is instance of "UserInterface".');
|
||||
}
|
||||
|
||||
if ($this->user instanceof EquatableInterface) {
|
||||
return ! (Boolean) $this->user->isEqualTo($user);
|
||||
}
|
||||
|
||||
if ($this->user->getPassword() !== $user->getPassword()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->user->getSalt() !== $user->getSalt()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->user->getUsername() !== $user->getUsername()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?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\Security\Token;
|
||||
|
||||
/**
|
||||
* TokenInterface is the interface for the user authentication information.
|
||||
*
|
||||
* Parts borrowed from Symfony Security Framework (Fabien Potencier <fabien@symfony.com> / Johannes M. Schmitt <schmittjoh@gmail.com>)
|
||||
*/
|
||||
|
||||
interface TokenInterface extends \Serializable
|
||||
{
|
||||
/**
|
||||
* Returns the user credentials.
|
||||
*
|
||||
* @return mixed The user credentials
|
||||
*/
|
||||
public function getCredentials();
|
||||
|
||||
/**
|
||||
* Returns a user representation.
|
||||
*
|
||||
* @return mixed either returns an object which implements __toString(), or
|
||||
* a primitive string is returned.
|
||||
*/
|
||||
public function getUser();
|
||||
|
||||
/**
|
||||
* Sets a user instance
|
||||
*
|
||||
* @param mixed $user
|
||||
*/
|
||||
public function setUser($user);
|
||||
|
||||
/**
|
||||
* Returns the username.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername();
|
||||
|
||||
/**
|
||||
* Returns whether the user is authenticated or not.
|
||||
*
|
||||
* @return Boolean true if the token has been authenticated, false otherwise
|
||||
*/
|
||||
public function isAuthenticated();
|
||||
|
||||
/**
|
||||
* Sets the authenticated flag.
|
||||
*
|
||||
* @param Boolean $isAuthenticated The authenticated flag
|
||||
*/
|
||||
public function setAuthenticated($isAuthenticated);
|
||||
|
||||
/**
|
||||
* Removes sensitive information from the token.
|
||||
*/
|
||||
public function eraseCredentials();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Security\Token;
|
||||
|
||||
use Thelia\Core\Security\User\UserInterface;
|
||||
|
||||
/**
|
||||
* UsernamePasswordToken implements a username and password token.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class UsernamePasswordToken extends AbstractToken
|
||||
{
|
||||
private $credentials;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method.
|
||||
* @param string $password The password of the user
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($username, $password, $authenticated = false)
|
||||
{
|
||||
$this->setUser($username);
|
||||
$this->credentials = $password;
|
||||
|
||||
parent::setAuthenticated($authenticated);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthenticated($isAuthenticated)
|
||||
{
|
||||
if ($isAuthenticated) {
|
||||
throw new \LogicException('Cannot set this token to trusted after instantiation.');
|
||||
}
|
||||
|
||||
parent::setAuthenticated(false);
|
||||
}
|
||||
|
||||
public function getCredentials()
|
||||
{
|
||||
return $this->credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eraseCredentials()
|
||||
{
|
||||
parent::eraseCredentials();
|
||||
|
||||
$this->credentials = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array($this->credentials, $this->providerKey, parent::serialize()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list($this->credentials, $this->providerKey, $parentStr) = unserialize($serialized);
|
||||
parent::unserialize($parentStr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
use Thelia\Core\Security\User\UserProviderInterface;
|
||||
use Thelia\Model\Admin;
|
||||
use Thelia\Core\Security\Encoder\PasswordEncoderInterface;
|
||||
|
||||
class AdminUserProvider implements UserProviderInterface {
|
||||
|
||||
public function getUser($key) {
|
||||
|
||||
$admin = new Admin();
|
||||
|
||||
$admin = AdminQuery::create()
|
||||
->filterByLogin($key)
|
||||
->findOne();
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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;
|
||||
|
||||
class CustomerUserProvider implements UserProviderInterface {
|
||||
|
||||
public function getUser($key) {
|
||||
|
||||
$customer = new Customer();
|
||||
|
||||
$customer = CustomerQuery::create()
|
||||
->filterByEmail($key)
|
||||
->findOne();
|
||||
|
||||
return $customer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Security\User;
|
||||
|
||||
/**
|
||||
* This interface should be implemented by user classes
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
interface UserInterface {
|
||||
|
||||
/**
|
||||
* Return the user unique name
|
||||
*/
|
||||
public function getUsername();
|
||||
|
||||
/**
|
||||
* Return the user encoded password
|
||||
*/
|
||||
public function getPassword();
|
||||
|
||||
/**
|
||||
* return the salt used to calculate the user password
|
||||
*/
|
||||
public function getSalt();
|
||||
|
||||
/**
|
||||
* return the algorithm used to calculate the user password
|
||||
*/
|
||||
public function getAlgo();
|
||||
|
||||
/**
|
||||
* Removes sensitive data from the user.
|
||||
*
|
||||
* This is important if, at any given point, sensitive information like
|
||||
* the plain-text password is stored on this object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function eraseCredentials();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Thelia\Core\Security\User;
|
||||
|
||||
interface UserProviderInterface {
|
||||
/**
|
||||
* Returns a UserInterface instance
|
||||
*
|
||||
* @param $key the unique user key (username, email address, etc.)
|
||||
* @return a UserInterface instance, or null if none was found.
|
||||
*/
|
||||
public function getUser($key);
|
||||
}
|
||||
?>
|
||||
@@ -29,12 +29,12 @@ class LoopResultRow
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->substitution["#".$key] = $value;
|
||||
$this->substitution[$key] = $value;
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
return $this->substitution["#".$key];
|
||||
return $this->substitution[$key];
|
||||
}
|
||||
|
||||
public function getVarVal()
|
||||
@@ -42,4 +42,9 @@ class LoopResultRow
|
||||
return $this->substitution;
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return array_keys($this->substitution);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class Assetic implements SmartyPluginInterface
|
||||
{
|
||||
$web_root = THELIA_WEB_DIR;
|
||||
|
||||
$asset_dir_from_web_root = '/assets/admin/default'; // FIXME
|
||||
$asset_dir_from_web_root = 'assets/admin/default'; // FIXME
|
||||
|
||||
$this->asset_manager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,30 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
*
|
||||
* Plugin for smarty defining blocks and functions for using Form display.
|
||||
*
|
||||
* blocks :
|
||||
* - {form name="myForm"} ... {/form} => find form named myForm,
|
||||
* create an instance and assign this instanciation into smarty variable. Form must be declare into
|
||||
* config using <forms> tag
|
||||
*
|
||||
* - {form_field form=$form.fieldName} {/form_field} This block find info into the Form field containing by
|
||||
* the form paramter. This field must be an instance of FormView. fieldName is the name of your field. This block
|
||||
* can output these info :
|
||||
* * $name => name of yout input
|
||||
* * $value => value for your input
|
||||
* * $label => label for your input
|
||||
* * $error => boolean for know if there is error for this field
|
||||
* * $attr => all your attribute for your input (define when you construct programmatically you form)
|
||||
*
|
||||
* - {form_error form=$form.fieldName} ... {/form_error} Display this block if there are errors on this field.
|
||||
* fieldName is the name of your field
|
||||
*
|
||||
* Class Form
|
||||
* @package Thelia\Core\Template\Smarty\Plugins
|
||||
*/
|
||||
class Form implements SmartyPluginInterface
|
||||
{
|
||||
|
||||
@@ -63,11 +87,7 @@ class Form implements SmartyPluginInterface
|
||||
throw new \InvalidArgumentException("Missing 'name' parameter in form arguments");
|
||||
}
|
||||
|
||||
$form = BaseForm::getFormFactory($this->request);
|
||||
$formBuilder = $form->createBuilder('form');
|
||||
|
||||
$instance = $this->getInstance($params['name']);
|
||||
$instance = $instance->buildForm($formBuilder, array());
|
||||
|
||||
$template->assign("form", $instance->getForm()->createView());
|
||||
} else {
|
||||
@@ -179,8 +199,10 @@ class Form implements SmartyPluginInterface
|
||||
throw new ElementNotFoundException(sprintf("%s form does not exists", $name));
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($this->formDefinition[$name]);
|
||||
|
||||
return new $this->formDefinition[$name];
|
||||
|
||||
return $class->newInstance($this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,9 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
|
||||
protected $dispatcher;
|
||||
|
||||
protected $loopstack = array();
|
||||
protected $varstack = array();
|
||||
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->request = $request;
|
||||
@@ -84,6 +87,10 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
$name = $params['name'];
|
||||
|
||||
if ($content === null) {
|
||||
// Check if a loop with the same name exists in the current scope, and abort if it's the case.
|
||||
if (array_key_exists($name, $this->varstack)) {
|
||||
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
|
||||
}
|
||||
|
||||
$loop = $this->createLoopInstance(strtolower($params['type']));
|
||||
|
||||
@@ -92,11 +99,10 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
self::$pagination[$name] = null;
|
||||
|
||||
$loopResults = $loop->exec(self::$pagination[$name]);
|
||||
$this->loopstack[$name] = $loopResults;
|
||||
|
||||
$template->assignByRef($name, $loopResults);
|
||||
|
||||
} else {
|
||||
$loopResults = $template->getTemplateVars($name);
|
||||
} else {
|
||||
$loopResults = $this->loopstack[$name];
|
||||
|
||||
$loopResults->next();
|
||||
}
|
||||
@@ -104,21 +110,50 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
if ($loopResults->valid()) {
|
||||
$loopResultRow = $loopResults->current();
|
||||
|
||||
// On first iteration, save variables that may be overwritten by this loop
|
||||
if (! isset($this->varstack[$name])) {
|
||||
|
||||
$saved_vars = array();
|
||||
|
||||
$varlist = $loopResultRow->getVars();
|
||||
$varlist[] = 'LOOP_COUNT';
|
||||
$varlist[] = 'LOOP_TOTAL';
|
||||
|
||||
foreach($varlist as $var) {
|
||||
$saved_vars[$var] = $template->getTemplateVars($var);
|
||||
}
|
||||
|
||||
$this->varstack[$name] = $saved_vars;
|
||||
}
|
||||
|
||||
foreach($loopResultRow->getVarVal() as $var => $val) {
|
||||
$template->assign(substr($var, 1), $val);
|
||||
$template->assign($var, $val);
|
||||
}
|
||||
|
||||
$template->assign('__COUNT__', 1 + $loopResults->key());
|
||||
$template->assign('__TOTAL__', $loopResults->getCount());
|
||||
// Assign meta information
|
||||
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
|
||||
$template->assign('LOOP_TOTAL', $loopResults->getCount());
|
||||
|
||||
//$repeat = $loopResults->valid();
|
||||
$repeat = true;
|
||||
}
|
||||
|
||||
// Loop is terminated. Cleanup.
|
||||
if (! $repeat) {
|
||||
// Restore previous variables values before terminating
|
||||
if (isset($this->varstack[$name])) {
|
||||
foreach($this->varstack[$name] as $var => $value) {
|
||||
$template->assign($var, $value);
|
||||
}
|
||||
|
||||
unset($this->varstack[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($content !== null) {
|
||||
if ($loopResults->isEmpty()) {
|
||||
$content = "";
|
||||
}
|
||||
|
||||
if ($loopResults->isEmpty()) $content = "";
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -177,10 +212,10 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
$loopName = $params['rel'];
|
||||
|
||||
// Find loop results in the current template vars
|
||||
$loopResults = $template->getTemplateVars($loopName);
|
||||
/* $loopResults = $template->getTemplateVars($loopName);
|
||||
if (empty($loopResults)) {
|
||||
throw new \InvalidArgumentException("Loop $loopName is not defined.");
|
||||
}
|
||||
}*/
|
||||
|
||||
// Find pagination
|
||||
$pagination = self::getPagination($loopName);
|
||||
@@ -224,14 +259,11 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
|
||||
$loopName = $params['rel'];
|
||||
|
||||
// Find loop results in the current template vars
|
||||
$loopResults = $template->getTemplateVars($loopName);
|
||||
|
||||
if (empty($loopResults)) {
|
||||
if (! isset($this->loopstack[$loopName])) {
|
||||
throw new \InvalidArgumentException("Loop $loopName is not defined.");
|
||||
}
|
||||
|
||||
return $loopResults->isEmpty();
|
||||
return $this->loopstack[$loopName]->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,9 +339,7 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
$value = (string)$argument->default;
|
||||
}
|
||||
|
||||
$test = $argument->type->getFormatedValue($value);
|
||||
|
||||
$loop->{$argument->name} = $value === null ? null : $test;
|
||||
$loop->{$argument->name} = $value === null ? null : $argument->type->getFormatedValue($value);
|
||||
}
|
||||
|
||||
if (!empty($faultActor)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ class Translation implements SmartyPluginInterface
|
||||
}
|
||||
|
||||
// TODO
|
||||
return "[$string]";
|
||||
return "$string";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,32 +23,28 @@
|
||||
namespace Thelia\Form;
|
||||
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
|
||||
class AdminLogin extends AbstractType {
|
||||
class AdminLogin extends BaseForm {
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
protected function buildForm()
|
||||
{
|
||||
return $builder
|
||||
$this->form
|
||||
->add("username", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank(),
|
||||
new Length(array("min" => 3))
|
||||
)
|
||||
))
|
||||
->add("password", "password");
|
||||
->add("password", "password", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
))
|
||||
->add("remember_me", "checkbox");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this type.
|
||||
*
|
||||
* @return string The name of this type
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "admin_login";
|
||||
}
|
||||
}
|
||||
@@ -32,30 +32,43 @@ use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class BaseForm {
|
||||
|
||||
abstract class BaseForm {
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Symfony\Component\Form\FormFactoryInterface
|
||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||
*/
|
||||
public static function getFormFactory(Request $request, $secret = null)
|
||||
protected $form;
|
||||
|
||||
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
|
||||
{
|
||||
$validator = Validation::createValidator();
|
||||
|
||||
$form = Forms::createFormFactoryBuilder()
|
||||
$this->form = Forms::createFormFactoryBuilder()
|
||||
->addExtension(new HttpFoundationExtension())
|
||||
->addExtension(
|
||||
new CsrfExtension(
|
||||
new SessionCsrfProvider(
|
||||
$request->getSession(),
|
||||
$secret ?: ConfigQuery::read("form.secret", md5(__DIR__))
|
||||
isset($option["secret"]) ? $option["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
|
||||
)
|
||||
)
|
||||
)
|
||||
->addExtension(new ValidatorExtension($validator))
|
||||
->getFormFactory();
|
||||
->getFormFactory()
|
||||
->createBuilder($type, $data, $options);
|
||||
;
|
||||
|
||||
return $form;
|
||||
$this->buildForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form->getForm();
|
||||
}
|
||||
|
||||
abstract protected function buildForm();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,31 +24,25 @@ namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
|
||||
class CustomerCreation extends AbstractType
|
||||
class CustomerCreation extends BaseForm
|
||||
{
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
protected function buildForm()
|
||||
{
|
||||
return $builder->add("name", "text")
|
||||
$this->form->add("name", "text")
|
||||
->add("email", "email", array(
|
||||
"attr" => array(
|
||||
"class" => "field"
|
||||
),
|
||||
"label" => "email"
|
||||
"label" => "email",
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
)
|
||||
)
|
||||
)
|
||||
->add('age', 'integer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this type.
|
||||
*
|
||||
* @return string The name of this type
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "customer creation";
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\om\BaseAdmin;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'admin' table.
|
||||
@@ -16,6 +16,27 @@ use Thelia\Model\om\BaseAdmin;
|
||||
*
|
||||
* @package propel.generator.Thelia.Model
|
||||
*/
|
||||
class Admin extends BaseAdmin
|
||||
class Admin extends BaseAdmin implements UserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getUsername() {
|
||||
return $this->getLogin();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function eraseCredentials() {
|
||||
$this->setPassword(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRoles() {
|
||||
return array(new Role('USER_CUSTOMER'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\om\BaseCustomer;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,6 +18,29 @@ use Thelia\Model\om\BaseCustomer;
|
||||
*
|
||||
* @package propel.generator.Thelia.Model
|
||||
*/
|
||||
class Customer extends BaseCustomer
|
||||
class Customer extends BaseCustomer implements UserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
public function getUsername() {
|
||||
return $this->getEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function eraseCredentials() {
|
||||
$this->setPassword(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRoles() {
|
||||
return array(new Role('USER_CUSTOMER'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use Thelia\Core\Security\Encoder\PasswordHashEncoder;
|
||||
|
||||
class PasswordHashEncoderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEncode()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$pass = $encoder->encode('password', 'sha512', 'a simple salt');
|
||||
|
||||
// echo "PASS=\{$pass\}";
|
||||
|
||||
$this->assertEquals("L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==", $pass, "Expected password not found.");
|
||||
}
|
||||
|
||||
public function testIsEqual()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertTrue($encoder->isEqual($exp, 'password', 'sha512', 'a simple salt'));
|
||||
}
|
||||
|
||||
public function testWrongPass()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'grongron', 'sha512', 'a simple salt'));
|
||||
}
|
||||
|
||||
public function testWrongSalt()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'password', 'sha512', 'another salt'));
|
||||
}
|
||||
|
||||
public function testWrongAlgo()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$this->assertFalse($encoder->isEqual($exp, 'password', 'md5', 'another salt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testUnsupportedAlgo()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$exp = "L3f/gGy4nBVhi8WSsC1a7E9JM8U+rtk6ZT+NiqX8M1UDJv6mahQEZ1z2cN/y9pixH+hgWbkBitONMiXWscomoQ==";
|
||||
|
||||
$encoder->isEqual($exp, 'password', 'sbonk', 'another salt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testEncodeWrongAlgorithm()
|
||||
{
|
||||
$encoder = new PasswordHashEncoder();
|
||||
|
||||
$encoder->encode('password', 'pouët', 'a simple salt');
|
||||
}
|
||||
}
|
||||
49
core/lib/Thelia/Tests/Core/Security/SecurityManagerTest.php
Normal file
49
core/lib/Thelia/Tests/Core/Security/SecurityManagerTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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\Tests\Security;
|
||||
|
||||
use Thelia\Core\Security\SecurityManager;
|
||||
/**
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
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());
|
||||
|
||||
$context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
|
||||
$this->assertSame($token, $context->getToken());
|
||||
*/
|
||||
// $this->assertFalse(1==1, "faux !");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user