4 * Contains \Drupal\Console\Command\User\PasswordResetCommand.
7 namespace Drupal\Console\Command\User;
9 use Symfony\Component\Console\Input\InputInterface;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Core\Database\Connection;
15 use Drupal\Console\Core\Utils\ChainQueue;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\user\Entity\User;
18 use Drupal\Console\Core\Style\DrupalStyle;
20 class PasswordResetCommand extends Command
23 use ConfirmationTrait;
33 protected $chainQueue;
36 * PasswordHashCommand constructor.
38 * @param Connection $database
39 * @param ChainQueue $chainQueue
41 public function __construct(
43 ChainQueue $chainQueue
45 $this->database = $database;
46 $this->chainQueue = $chainQueue;
47 parent::__construct();
53 protected function configure()
56 ->setName('user:password:reset')
57 ->setDescription($this->trans('commands.user.password.reset.description'))
58 ->setHelp($this->trans('commands.user.password.reset.help'))
59 ->addArgument('user', InputArgument::REQUIRED, $this->trans('commands.user.password.reset.options.user-id'))
60 ->addArgument('password', InputArgument::REQUIRED, $this->trans('commands.user.password.reset.options.password'));
66 protected function execute(InputInterface $input, OutputInterface $output)
68 $io = new DrupalStyle($input, $output);
70 $uid = $input->getArgument('user');
72 $user = User::load($uid);
77 $this->trans('commands.user.password.reset.errors.invalid-user'),
85 $password = $input->getArgument('password');
89 $this->trans('commands.user.password.reset.errors.empty-password'),
98 $user->setPassword($password);
101 $schema = $this->database->schema();
102 $flood = $schema->findTables('flood');
105 $this-$this->chainQueue
106 ->addCommand('user:login:clear:attempts', ['uid' => $uid]);
108 } catch (\Exception $e) {
109 $io->error($e->getMessage());
116 $this->trans('commands.user.password.reset.messages.reset-successful'),
125 protected function interact(InputInterface $input, OutputInterface $output)
127 $io = new DrupalStyle($input, $output);
129 $user = $input->getArgument('user');
133 $this->trans('commands.user.password.reset.questions.user'),
135 function ($uid) use ($io) {
138 if (is_int($uid) && $uid > 0) {
142 sprintf($this->trans('commands.user.password.reset.questions.invalid-uid'), $uid)
156 $input->setArgument('user', $user);
159 $password = $input->getArgument('password');
162 $password = $io->ask(
163 $this->trans('commands.user.password.hash.questions.password'),
165 function ($pass) use ($io) {
171 sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass)
186 $input->setArgument('password', $password);