From 2ee90d35e4b234c7705490a69f8ed141aaccf9b7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 14:27:45 +0100 Subject: [PATCH 1/4] create administrator update password event --- .../AdministratorUpdatePasswordEvent.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php new file mode 100644 index 000000000..70f92532b --- /dev/null +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Administrator; +use Thelia\Core\Event\ActionEvent; + + +/** + * Class AdministratorUpdatePasswordEvent + * @package Thelia\Core\Event\Administrator + * @author Manuel Raynaud + */ +class AdministratorUpdatePasswordEvent extends ActionEvent +{ + + /** + * @var string administrator login + */ + protected $login; + + /** + * @var string new administrator password + */ + protected $password; + + public function __construct($login) + { + $this->login = $login; + } + + /** + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $login + */ + public function setLogin($login) + { + $this->login = $login; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + +} \ No newline at end of file From 9d011eb5c67b40174eb5d8e89f1e80c8c5c96fa4 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 14:46:21 +0100 Subject: [PATCH 2/4] change command line for creating new administrator --- core/lib/Thelia/Command/CreateAdminUser.php | 2 +- reset_install.bat | 2 +- reset_install.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 857790141..5ac62802a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -38,7 +38,7 @@ class CreateAdminUser extends ContainerAwareCommand protected function configure() { $this - ->setName("thelia:create-admin") + ->setName("admin:create") ->setDescription("Create a new adminsitration user") ->setHelp("The thelia:create-admin command create a new administration user.") ->addOption( diff --git a/reset_install.bat b/reset_install.bat index 0a12c43d2..f8c0b35e2 100644 --- a/reset_install.bat +++ b/reset_install.bat @@ -26,7 +26,7 @@ if exist local\config\database.yml ( php install\faker.php echo [INFO] Adding admin - php Thelia thelia:create-admin + php Thelia admin:create echo [SUCCESS] Reset done ) diff --git a/reset_install.sh b/reset_install.sh index a91a2dc1c..83288a509 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -32,7 +32,7 @@ echo -e "\n\033[01;34m[INFO] Installing fixtures\033[00m\n" php install/faker.php echo -e "\n\033[01;34m[INFO] Adding admin\033[00m\n" -php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 +php Thelia admin:create --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 echo -e "\n\033[01;34m[INFO] Clearing caches\033[00m\n" php Thelia cache:clear From b0f3ad69d2e9fbc89f9594535bc5b3c21b955ff9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:01:18 +0100 Subject: [PATCH 3/4] start creating admin password recovery --- core/lib/Thelia/Action/Administrator.php | 16 ++++- .../Thelia/Command/AdminUpdatePassword.php | 63 +++++++++++++++++++ core/lib/Thelia/Command/CreateAdminUser.php | 4 +- .../AdministratorUpdatePasswordEvent.php | 2 +- core/lib/Thelia/Core/Event/TheliaEvents.php | 1 + 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 core/lib/Thelia/Command/AdminUpdatePassword.php diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 2bbfce8a8..23167dd40 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -25,6 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Administrator\AdministratorEvent; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Admin as AdminModel; use Thelia\Model\AdminQuery; @@ -92,15 +93,24 @@ class Administrator extends BaseAction implements EventSubscriberInterface } } + public function updatePassword(AdministratorUpdatePasswordEvent $event) + { + if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { + $admin->setPassword($event->getPassword()) + ->save(); + } + } + /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::ADMINISTRATOR_CREATE => array("create", 128), - TheliaEvents::ADMINISTRATOR_UPDATE => array("update", 128), - TheliaEvents::ADMINISTRATOR_DELETE => array("delete", 128), + TheliaEvents::ADMINISTRATOR_CREATE => array('create', 128), + TheliaEvents::ADMINISTRATOR_UPDATE => array('update', 128), + TheliaEvents::ADMINISTRATOR_DELETE => array('delete', 128), + TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD => array('updatePassword', 128) ); } } diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePassword.php new file mode 100644 index 000000000..6b0a0ec48 --- /dev/null +++ b/core/lib/Thelia/Command/AdminUpdatePassword.php @@ -0,0 +1,63 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; + + +/** + * command line for updating admin password + * + * php Thelia admin:updatePassword + * + * Class AdminUpdatePassword + * @package Thelia\Command + * @author Manuel Raynaud + */ +class AdminUpdatePassword extends ContainerAwareCommand +{ + + /** + * Configures the current command. + */ + protected function configure() + { + $this + ->setName('admin:updatePassword') + ->setDescription('change administrator password') + ->setHelp('The admin:updatePassword command allows you to change the password for a given administrator') + ->addArgument( + 'login', + InputArgument::REQUIRED, + 'Login for administrator you want to change the password' + ) + ->addOption( + 'password', + null, + InputOption::VALUE_REQUIRED, + 'Desired password. If this option is omitted, a random password is generated and shown in this prompt after' + ) + ; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index 5ac62802a..988122e7a 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -39,8 +39,8 @@ class CreateAdminUser extends ContainerAwareCommand { $this ->setName("admin:create") - ->setDescription("Create a new adminsitration user") - ->setHelp("The thelia:create-admin command create a new administration user.") + ->setDescription("Create a new administrator user") + ->setHelp("The admin:create command create a new administration user.") ->addOption( 'login_name', null, diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index 70f92532b..cccb45cc4 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -80,5 +80,5 @@ class AdministratorUpdatePasswordEvent extends ActionEvent return $this->login; } - + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 42b20d8cd..ea3d7686a 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -565,6 +565,7 @@ final class TheliaEvents const ADMINISTRATOR_CREATE = "action.createAdministrator"; const ADMINISTRATOR_UPDATE = "action.updateAdministrator"; const ADMINISTRATOR_DELETE = "action.deleteAdministrator"; + const ADMINISTRATOR_UPDATEPASSWORD = 'action.generatePassword'; // -- Mailing System management --------------------------------------------- From e18c8992f82ecc5882803c1733cd09e2ecf970d8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:33:25 +0100 Subject: [PATCH 4/4] finish admin update password command line --- core/lib/Thelia/Action/Administrator.php | 7 ++-- ...ord.php => AdminUpdatePasswordCommand.php} | 41 ++++++++++++++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../AdministratorUpdatePasswordEvent.php | 23 ++++++----- local/modules/Cheque/Config/config.xml | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) rename core/lib/Thelia/Command/{AdminUpdatePassword.php => AdminUpdatePasswordCommand.php} (70%) diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 23167dd40..15940082a 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -95,10 +95,9 @@ class Administrator extends BaseAction implements EventSubscriberInterface public function updatePassword(AdministratorUpdatePasswordEvent $event) { - if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { - $admin->setPassword($event->getPassword()) - ->save(); - } + $admin = $event->getAdmin(); + $admin->setPassword($event->getPassword()) + ->save(); } /** diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php similarity index 70% rename from core/lib/Thelia/Command/AdminUpdatePassword.php rename to core/lib/Thelia/Command/AdminUpdatePasswordCommand.php index 6b0a0ec48..d4d0e5fc8 100644 --- a/core/lib/Thelia/Command/AdminUpdatePassword.php +++ b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php @@ -22,8 +22,15 @@ /*************************************************************************************/ namespace Thelia\Command; + use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\AdminQuery; +use Thelia\Tools\Password; /** @@ -31,11 +38,11 @@ use Symfony\Component\Console\Input\InputOption; * * php Thelia admin:updatePassword * - * Class AdminUpdatePassword + * Class AdminUpdatePasswordCommand * @package Thelia\Command * @author Manuel Raynaud */ -class AdminUpdatePassword extends ContainerAwareCommand +class AdminUpdatePasswordCommand extends ContainerAwareCommand { /** @@ -60,4 +67,34 @@ class AdminUpdatePassword extends ContainerAwareCommand ) ; } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $login = $input->getArgument('login'); + + + if (null === $admin = AdminQuery::create()->filterByLogin($login)->findOne()) { + throw new \RuntimeException(sprintf('Admin with login %s does not exists', $login)); + } + + + $password = $input->getOption('password') ?: Password::generateRandom(); + + $event = new AdministratorUpdatePasswordEvent($admin); + $event->setPassword($password); + + + $this-> + getContainer() + ->get('event_dispatcher') + ->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event); + + $output->writeln(array( + '', + sprintf('admin %s password updated', $login), + sprintf('new password is : %s', $password), + '' + )); + + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c0af99896..255f70dfd 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -182,6 +182,7 @@ + diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index cccb45cc4..01a36a206 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -23,6 +23,7 @@ namespace Thelia\Core\Event\Administrator; use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Admin; /** @@ -34,18 +35,18 @@ class AdministratorUpdatePasswordEvent extends ActionEvent { /** - * @var string administrator login + * @var \Thelia\Model\Admin */ - protected $login; + protected $admin; /** * @var string new administrator password */ protected $password; - public function __construct($login) + public function __construct(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** @@ -65,20 +66,22 @@ class AdministratorUpdatePasswordEvent extends ActionEvent } /** - * @param string $login + * @param \Thelia\Model\Admin $admin */ - public function setLogin($login) + public function setAdmin(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** - * @return string + * @return \Thelia\Model\Admin */ - public function getLogin() + public function getAdmin() { - return $this->login; + return $this->admin; } + + } \ No newline at end of file diff --git a/local/modules/Cheque/Config/config.xml b/local/modules/Cheque/Config/config.xml index 2430f5027..cac3f6b7b 100755 --- a/local/modules/Cheque/Config/config.xml +++ b/local/modules/Cheque/Config/config.xml @@ -1,4 +1,4 @@ - +string