From b0f3ad69d2e9fbc89f9594535bc5b3c21b955ff9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:01:18 +0100 Subject: [PATCH] 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 ---------------------------------------------