finish admin update password command line

This commit is contained in:
Manuel Raynaud
2013-10-30 15:33:25 +01:00
parent 66c30a1b4c
commit 78cba61cd5
5 changed files with 57 additions and 17 deletions

View File

@@ -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();
}
/**

View File

@@ -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 <mraynaud@openstudio.fr>
*/
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('<info>admin %s password updated</info>', $login),
sprintf('<info>new password is : %s</info>', $password),
''
));
}
}

View File

@@ -182,6 +182,7 @@
<command class="Thelia\Command\CreateAdminUser"/>
<command class="Thelia\Command\ReloadDatabaseCommand"/>
<command class="Thelia\Command\GenerateResources"/>
<command class="Thelia\Command\AdminUpdatePasswordCommand"/>
</commands>
<services>

View File

@@ -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;
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>string
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"