|
@@ -0,0 +1,66 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace AppBundle\Command;
|
|
|
+
|
|
|
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use Symfony\Component\Console\Question\ChoiceQuestion;
|
|
|
+use Symfony\Component\Console\Question\Question;
|
|
|
+use AppBundle\Service\UserManager;
|
|
|
+
|
|
|
+class AppUserCreateCommand extends ContainerAwareCommand
|
|
|
+{
|
|
|
+ private $userManager;
|
|
|
+
|
|
|
+ public function __construct(UserManager $userManager)
|
|
|
+ {
|
|
|
+ $this->userManager = $userManager;
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('app:user:create')
|
|
|
+ ->setDescription('Créer un utilisateur')
|
|
|
+ ->addArgument('argument', InputArgument::OPTIONAL, 'Argument description')
|
|
|
+ ->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ $helper = $this->getHelper('question');
|
|
|
+ $questionUsername = new Question('Nom (username) de l\'utilisateur : ', 'admin_user');
|
|
|
+ $questionPrenom = new Question('Prénom de l\'utilisateur : ', 'Toto');
|
|
|
+ $questionNom = new Question('Nom de l\'utilisateur : ', 'Titi');
|
|
|
+ $questionPassword = new Question('Mot de passe :', 'MotDePasse');
|
|
|
+ $questionPassword->setHidden(true);
|
|
|
+ $questionPassword->setHiddenFallback(false);
|
|
|
+ $questionMail = new Question('Email :', 'bidule@truc.chose');
|
|
|
+ $questionRole = new ChoiceQuestion('Roles :', array('ROLE_SUPER_ADMIN', 'ROLE_ADMIN', 'ROLE_USER', 'ROLE_MODERATEUR'), '0');
|
|
|
+ $questionRole->setMultiselect(true);
|
|
|
+
|
|
|
+ $username = $helper->ask($input, $output, $questionUsername);
|
|
|
+ $nom = $helper->ask($input, $output, $questionNom);
|
|
|
+ $prenom = $helper->ask($input, $output, $questionPrenom);
|
|
|
+ $mail = $helper->ask($input, $output, $questionMail);
|
|
|
+ $password = $helper->ask($input, $output, $questionPassword);
|
|
|
+ $roles = $helper->ask($input, $output, $questionRole);
|
|
|
+
|
|
|
+ $this->userManager->createUser(
|
|
|
+ "$username",
|
|
|
+ "$password",
|
|
|
+ "$nom",
|
|
|
+ "$prenom",
|
|
|
+ "$mail",
|
|
|
+ $roles,
|
|
|
+ true);
|
|
|
+
|
|
|
+ $output->writeln('Nom du pélo : '.$username);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|