diff --git a/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php new file mode 100644 index 000000000..81db900d8 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php @@ -0,0 +1,45 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Form\Form; + +use Thelia\Core\Security\UserProvider\AdminUserProvider; +use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator; + +class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator { + + public function __construct(Request $request, Form $loginForm) { + parent::__construct( + $request, + $loginForm, + new AdminUserProvider(), + array( + 'username_field_name', 'email' + ) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/Authentication/AuthenticatorInterface.php b/core/lib/Thelia/Core/Security/Authentication/AuthenticatorInterface.php new file mode 100644 index 000000000..05d850bee --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/AuthenticatorInterface.php @@ -0,0 +1,32 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +interface AuthenticatorInterface { + + /** + * Returns a UserInterface instance, authentified using the authenticator specific method + */ + public function getAuthentifiedUser(); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php new file mode 100644 index 000000000..483894b93 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php @@ -0,0 +1,40 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Symfony\Component\HttpFoundation\Request; +use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator; +use Thelia\Form\CustomerLogin; + +class CustomerUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator { + + public function __construct(Request $request, AdminLogin $loginForm) { + parent::__construct( + $request, + $loginForm, + new AdminUserProvider(), + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php new file mode 100644 index 000000000..37156786c --- /dev/null +++ b/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php @@ -0,0 +1,91 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Authentication; + +use Thelia\Core\Security\Authentication\AuthenticatorInterface; +use Symfony\Component\HttpFoundation\Request; +use Thelia\Core\Security\UserProvider\UserProviderInterface; +use Symfony\Component\Form\Form; +use Thelia\Core\Security\Exception\WrongPasswordException; +use Thelia\Core\Security\Exception\UsernameNotFoundException; + +class UsernamePasswordFormAuthenticator implements AuthenticatorInterface { + + protected $request; + protected $loginForm; + protected $userProvider; + protected $options; + + + public function __construct(Request $request, Form $loginForm, UserProviderInterface $userProvider, array $options = array()) { + $this->request = $request; + $this->loginForm = $loginForm; + $this->userProvider = $userProvider; + + $defaults = array( + 'required_method' => 'POST', + 'username_field_name' => 'username', + 'password_field_name' => 'password' + ); + + $this->options = array_merge($defaults, $options); + + $this->loginForm->bind($this->request); + } + + public function getLoginForm() { + return $this->loginForm; + } + + public function getUsername() { + return $this->loginForm->get($this->options['username_field_name'])->getData(); + } + + public function getAuthentifiedUser() { + + if ($this->request->isMethod($this->options['required_method'])) { + + if ($this->loginForm->isValid()) { + + // Retreive user + $username = $this->getUsername(); + $password = $this->loginForm->get($this->options['password_field_name'])->getData(); + + $user = $this->userProvider->getUser($username); + + if ($user === null) throw new UsernameNotFoundException(sprintf("Username '%s' was not found.", $username)); + + // Check user password + $authOk = $user->checkPassword($password) === true; + + if ($authOk !== true) throw new WrongPasswordException(sprintf("Wrong password for user '%s'.", $username)); + + return $user; + } + } + else { + throw new \RuntimeException("Invalid method."); + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/Exception/AuthenticationException.php b/core/lib/Thelia/Core/Security/Exception/AuthenticationException.php new file mode 100644 index 000000000..2e3e496a3 --- /dev/null +++ b/core/lib/Thelia/Core/Security/Exception/AuthenticationException.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Exception; + +class AuthenticationException extends \Exception +{ +} diff --git a/core/lib/Thelia/Core/Security/Exception/UsernameNotFoundException.php b/core/lib/Thelia/Core/Security/Exception/UsernameNotFoundException.php new file mode 100644 index 000000000..2168e63ca --- /dev/null +++ b/core/lib/Thelia/Core/Security/Exception/UsernameNotFoundException.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Exception; + +class UsernameNotFoundException extends AuthenticationException +{ +} diff --git a/core/lib/Thelia/Core/Security/Exception/WrongPasswordException.php b/core/lib/Thelia/Core/Security/Exception/WrongPasswordException.php new file mode 100644 index 000000000..6088f43ad --- /dev/null +++ b/core/lib/Thelia/Core/Security/Exception/WrongPasswordException.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Security\Exception; + +class WrongPasswordException extends AuthenticationException +{ +} diff --git a/core/lib/Thelia/Core/Translation/Translator.php b/core/lib/Thelia/Core/Translation/Translator.php new file mode 100644 index 000000000..f884b0c98 --- /dev/null +++ b/core/lib/Thelia/Core/Translation/Translator.php @@ -0,0 +1,28 @@ +getLocale(); + } + + if (!isset($this->catalogues[$locale])) { + $this->loadCatalogue($locale); + } + + if ($this->catalogues[$locale]->has((string) $id, $domain)) + return parent::trans($id, $parameters, $domain = 'messages', $locale = null); + else + return strtr($id, $parameters); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/CustomerLogin.php b/core/lib/Thelia/Form/CustomerLogin.php new file mode 100644 index 000000000..e18947d1b --- /dev/null +++ b/core/lib/Thelia/Form/CustomerLogin.php @@ -0,0 +1,55 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Validator\Constraints\Length; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\Choice; + +class CustomerLogin extends BaseForm { + + protected function buildForm() + { + $this->form + ->add("username", "text", array( + "constraints" => array( + new NotBlank(), + new Length(array("min" => 3)) + ) + )) + ->add("password", "password", array( + "constraints" => array( + new NotBlank() + ) + )) + ->add("remember_me", "checkbox") + ; + } + + public function getName() + { + return "customer_login"; + } +} diff --git a/install/INSTALL-TODO.txt b/install/INSTALL-TODO.txt new file mode 100644 index 000000000..91662f2b7 --- /dev/null +++ b/install/INSTALL-TODO.txt @@ -0,0 +1,9 @@ +A faire dans la procédure d'install +----------------------------------- + +Variables Config à initialiser: + +- base_url : url de base de la boutique avec / final (ex. http://www.boutique.com/, ou http://www.boutique.com/path/to/thelia2/ ) +- base_admin_template : chemin du template admin relatif au repertoire template (ex. admin/default) +- default_locale : la locale par défaut (ex. en_US), à utiliser pour les fichiers de traduction +- asset_dir_from_web_root : le chemin relatif à /web du repertoires des assets (ex. assets)