mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
resolving deprecated private service injection on commands classes
This commit is contained in:
@@ -20,19 +20,41 @@
|
||||
|
||||
namespace Chill\MainBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* Description of SetPasswordCommand
|
||||
* Class SetPasswordCommand
|
||||
*
|
||||
* @package Chill\MainBundle\Command
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class SetPasswordCommand extends ContainerAwareCommand
|
||||
class SetPasswordCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* SetPasswordCommand constructor.
|
||||
*
|
||||
* @param EntityManager $entityManager
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('chill:user:set_password')
|
||||
@@ -64,17 +86,21 @@ class SetPasswordCommand extends ContainerAwareCommand
|
||||
|
||||
public function _getUser($username)
|
||||
{
|
||||
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||
return $em->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => $username));
|
||||
return $this->entityManager
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => $username));
|
||||
}
|
||||
|
||||
public function _setPassword(User $user, $password)
|
||||
{
|
||||
$encoder = $this->getContainer()->get('security.encoder_factory')
|
||||
->getEncoder($user);
|
||||
$user->setPassword($encoder->encodePassword($password, $user->getSalt()));
|
||||
$this->getContainer()->get('doctrine.orm.entity_manager')
|
||||
->flush($user);
|
||||
$defaultEncoder = new MessageDigestPasswordEncoder('sha512', true, 5000);
|
||||
$encoders = [
|
||||
User::class => $defaultEncoder
|
||||
];
|
||||
$encoderFactory = new EncoderFactory($encoders);
|
||||
$user->setPassword(
|
||||
$encoderFactory->getEncoder($user)->encodePassword($password, $user->getSalt())
|
||||
);
|
||||
$this->entityManager->flush($user);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user