diff --git a/bin/console b/bin/console index e2154bd2ab..8a3a6a632c 100755 --- a/bin/console +++ b/bin/console @@ -49,6 +49,7 @@ use Alchemy\Phrasea\Command\Task\TaskStart; use Alchemy\Phrasea\Command\Task\TaskState; use Alchemy\Phrasea\Command\Task\TaskStop; use Alchemy\Phrasea\Command\User\UserCreateCommand; +use Alchemy\Phrasea\Command\User\UserSetPasswordCommand; use Alchemy\Phrasea\Command\User\UserListCommand; use Alchemy\Phrasea\Command\UpgradeDBDatas; @@ -117,8 +118,9 @@ $cli->command(new ListCollectionCommand('collection:list')); $cli->command(new ListDataboxCommand('databox:list')); $cli->command(new CreateDataboxCommand('databox:create')); - $cli->command(new UserCreateCommand('user:create')); +$cli->command(new UserSetPasswordCommand('user:set-password')); + $cli->command(new UserListCommand('user:list')); diff --git a/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php new file mode 100644 index 0000000000..963910db02 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php @@ -0,0 +1,79 @@ +setDescription('Set user password in Phraseanet') + ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') + ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password') + ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password') + ->setHelp(''); + + return $this; + } + + protected function doExecute(InputInterface $input, OutputInterface $output) + { + + $dialog = $this->getHelperSet()->get('dialog'); + $userRepository = $this->container['repo.users']; + $userManipulator = $this->container['manipulator.user']; + $user = $userRepository->find($input->getOption('user_id')); + $password = $input->getOption('password'); + $generate = $input->getOption('generate'); + + if ($user === null) { + $output->writeln('Not found User.'); + return 0; + } + + if ($generate) { + $password = $this->container['random.medium']->generateString(64); + } else { + if (!$password) { + $output->writeln('--password option not specified'); + return 0; + } + } + + do { + $continue = mb_strtolower($dialog->ask($output, 'Do you want really set password to this user? (y/N)', 'N')); + } while (!in_array($continue, ['y', 'n'])); + + if ($continue !== 'y') { + $output->writeln('Aborting !'); + + return; + } + + $userManipulator->setPassword($user,$password); + $output->writeln('New password: ' . $password . ''); + + return 0; + } + +}