partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit c7beb6b44d9ea47521f1fec197cfc32d0160c5bb
parent f526691d167ef4bd3c52311f3d0a1b8ed217d96f
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed,  8 Jul 2015 20:31:29 +0200

Added command to set the password

Diffstat:
Asrc/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/AuthBundle/PartKeeprAuthBundle.php | 2++
2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/src/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php b/src/PartKeepr/AuthBundle/Console/Command/SetPasswordCommand.php @@ -0,0 +1,66 @@ +<?php +namespace PartKeepr\AuthBundle\Console\Command; + +use Doctrine\ORM\EntityManager; +use PartKeepr\AuthBundle\Entity\User\User; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Class SetPasswordCommand + * + * Implements the command to change the password of an user + * + * @package PartKeepr\AuthBundle\Console\Command + */ +class SetPasswordCommand extends ContainerAwareCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('partkeepr:user:password') + ->setDescription('Changes the password of an user') + ->addArgument( + 'username', + InputArgument::REQUIRED, + 'The username' + ) + ->addArgument( + 'password', + InputArgument::REQUIRED, + 'The password' + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $username = $input->getArgument('username'); + $password = $input->getArgument('password'); + + /** + * @var $entityManager EntityManager + */ + $entityManager = $this->getContainer()->get('doctrine')->getManager(); + $repository = $entityManager->getRepository( + "PartKeepr\AuthBundle\Entity\User\User" + ); + + /** + * @var $user User + */ + $user = $repository->findOneBy(array("username" => $username)); + $user->setPassword($password); + + $entityManager->flush(); + + $output->writeln("Password changed"); + } +}+ \ No newline at end of file diff --git a/src/PartKeepr/AuthBundle/PartKeeprAuthBundle.php b/src/PartKeepr/AuthBundle/PartKeeprAuthBundle.php @@ -3,6 +3,7 @@ namespace PartKeepr\AuthBundle; use PartKeepr\AuthBundle\Console\Command\CreateUserCommand; +use PartKeepr\AuthBundle\Console\Command\SetPasswordCommand; use Symfony\Component\Console\Application; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -14,5 +15,6 @@ class PartKeeprAuthBundle extends Bundle public function registerCommands(Application $application) { $application->add(new CreateUserCommand()); + $application->add(new SetPasswordCommand()); } }