mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,101 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Command;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use LogicException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Class SetPasswordCommand
|
||||
*
|
||||
* @package Chill\MainBundle\Command
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Class SetPasswordCommand.
|
||||
*/
|
||||
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')
|
||||
->setDescription('set a password to user')
|
||||
->addArgument('username', InputArgument::REQUIRED, 'the user\'s '
|
||||
. 'username you want to change password')
|
||||
->addArgument('password', InputArgument::OPTIONAL, 'the new password')
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$user = $this->_getUser($input->getArgument('username'));
|
||||
|
||||
if ($user === NULL) {
|
||||
throw new \LogicException("The user with username '".
|
||||
$input->getArgument('username')."' is not found");
|
||||
}
|
||||
|
||||
$password = $input->getArgument('password');
|
||||
if ($password === NULL) {
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$password = $dialog->askHiddenResponse($output, "<question>the new password :"
|
||||
. "</question>");
|
||||
}
|
||||
|
||||
$this->_setPassword($user, $password);
|
||||
}
|
||||
|
||||
|
||||
public function _getUser($username)
|
||||
{
|
||||
return $this->entityManager
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => $username));
|
||||
->findOneBy(['username' => $username]);
|
||||
}
|
||||
|
||||
|
||||
public function _setPassword(User $user, $password)
|
||||
{
|
||||
$defaultEncoder = new MessageDigestPasswordEncoder('sha512', true, 5000);
|
||||
$encoders = [
|
||||
User::class => $defaultEncoder
|
||||
User::class => $defaultEncoder,
|
||||
];
|
||||
$encoderFactory = new EncoderFactory($encoders);
|
||||
$user->setPassword(
|
||||
@@ -103,4 +57,33 @@ class SetPasswordCommand extends Command
|
||||
);
|
||||
$this->entityManager->flush($user);
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('chill:user:set_password')
|
||||
->setDescription('set a password to user')
|
||||
->addArgument('username', InputArgument::REQUIRED, 'the user\'s '
|
||||
. 'username you want to change password')
|
||||
->addArgument('password', InputArgument::OPTIONAL, 'the new password');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$user = $this->_getUser($input->getArgument('username'));
|
||||
|
||||
if (null === $user) {
|
||||
throw new LogicException("The user with username '" .
|
||||
$input->getArgument('username') . "' is not found");
|
||||
}
|
||||
|
||||
$password = $input->getArgument('password');
|
||||
|
||||
if (null === $password) {
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$password = $dialog->askHiddenResponse($output, '<question>the new password :'
|
||||
. '</question>');
|
||||
}
|
||||
|
||||
$this->_setPassword($user, $password);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user