Ejemplo n.º 1
0
 /**
  * Informs the display about the structure of a Field.
  * 
  * Each time the Field structure changes for some reason, this method shall
  * be called.
  *
  * @param \Feeld\Display\DisplayDataSourceInterface $field
  * @throws Exception
  */
 public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field)
 {
     parent::informAboutStructure($field);
     $this->field = $field;
     if ($field instanceof \Feeld\Field\Entry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
     } elseif ($field instanceof \Feeld\Field\Select) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ChoiceQuestion((string) $this, array_keys($field->getOptions()), $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         if ($field instanceof \Feeld\Field\CommonProperties\MultipleChoiceInterface && $field->isMultipleChoice()) {
             $field->symfonyQuestion->setMultiselect(true);
         }
     } elseif ($field instanceof \Feeld\Field\CloakedEntry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         $this->symfonyQuestion->setHidden(true);
     } elseif ($field instanceof \Feeld\Field\Constant) {
         throw new Exception('Constants are currently not supported in SymfonyConsoleDisplay');
     } elseif ($field instanceof \Feeld\Field\Checkbox) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ConfirmationQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : true, '/^' . strtolower(substr($this->getTrueOption(), 0, 1)) . '/i');
     }
     $this->symfonyQuestion->setNormalizer(function ($value) {
         return $this->field->getSanitizer()->filter($value);
     });
     $this->symfonyQuestion->setValidator(function ($value) {
         $validationResultSet = $this->field->validateValue($value);
         if ($validationResultSet->hasErrors()) {
             $this->field->clearValidationResult();
             throw new \Exception(implode(PHP_EOL, $validationResultSet->getErrorMessages()));
         }
         return $this->field->getFilteredValue();
     });
     $this->symfonyQuestion->setMaxAttempts(null);
 }
Ejemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $email = $input->getOption('email');
     $pass = $input->getOption('password');
     $roles = explode(",", $input->getOption('roles'));
     $helper = $this->getHelper('question');
     if (!$email) {
         $question = new Question('Please enter a email address : ', 'email');
         $email = $helper->ask($input, $output, $question);
     }
     if (!$pass) {
         $question = new Question('Please enter a password : '******'password');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $pass = $helper->ask($input, $output, $question);
     }
     if (!\ProcessWire\wire("pages")->get("name={$name}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<error>User '{$name}' already exists!</error>");
         exit(1);
     }
     $user = $this->createUser($email, $name, $this->userContainer, $pass);
     $user->save();
     if ($input->getOption('roles')) {
         $this->attachRolesToUser($name, $roles, $output);
     }
     if ($pass) {
         $output->writeln("<info>User '{$name}' created successfully!</info>");
     } else {
         $output->writeln("<info>User '{$name}' created successfully! Please do not forget to set a password.</info>");
     }
 }
 /**
  * Execute the command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = $input->getOption('db');
     if (empty($db)) {
         throw new \InvalidArgumentException('You must define the database name with --db');
     }
     $password = $input->getOption('password');
     if (is_null($password)) {
         $helper = $this->getHelper('question');
         $question = new Question('Password: '******'host'), $input->getOption('user'), $password);
     } catch (\Exception $e) {
         throw new \RuntimeException("Can't connect to the database. Check your credentials");
     }
     $writer = new \Inet\Neuralyzer\Configuration\Writer();
     $ignoreFields = $input->getOption('ignore-field');
     $writer->protectCols($input->getOption('protect'));
     // Override the protection if fields are defined
     if (!empty($ignoreFields)) {
         $writer->protectCols(true);
         $writer->setProtectedCols($ignoreFields);
     }
     $writer->setIgnoredTables($input->getOption('ignore-table'));
     $data = $writer->generateConfFromDB($pdo, new \Inet\Neuralyzer\Guesser());
     $writer->save($data, $input->getOption('file'));
     $output->writeln('<comment>Configuration written to ' . $input->getOption('file') . '</comment>');
 }
Ejemplo n.º 4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $username = $helper->ask($input, $output, new Question('Username: '******'Password: '******'Username: <info>' . $username . '</info>');
     $output->writeln('Roles:    <info>' . implode(', ', $roles) . '</info>');
     $this->showRoleWarnings($roles, $output);
     if (!$helper->ask($input, $output, new ConfirmationQuestion('Create user? [y/N]: ', false))) {
         return;
     }
     $provider = $this->getContainer()->get('orm.user_provider');
     $provider->createUser($username, $password, $roles);
     $output->writeln("Created new user");
 }
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questions = array();
     if (!$input->getArgument('username')) {
         $question = new Question('Please give the username:'******'Username can not be empty');
             }
             return $username;
         });
         $questions['username'] = $question;
     }
     if (!$input->getArgument('password')) {
         $question = new Question('Please enter the new password:'******'Password can not be empty');
             }
             return $password;
         });
         $question->setHidden(true);
         $questions['password'] = $question;
     }
     foreach ($questions as $name => $question) {
         $answer = $this->getHelper('question')->ask($input, $output, $question);
         $input->setArgument($name, $answer);
     }
 }
Ejemplo n.º 6
0
 public function handle(InputInterface $input, OutputInterface $output)
 {
     $data = [];
     $helper = $this->command->getHelper('question');
     $data['jiraHost'] = $helper->ask($input, $output, new Question('Domain (yourdomain.atlassian.net): ', false));
     $data['jiraUser'] = $helper->ask($input, $output, new Question('Username: '******'Password: '******'Confirm Password: '******'Password cannot be blank');
     //        }
     //
     //        if ($password !== $password2) {
     //            throw new \RuntimeException('Passwords must match.');
     //        }
     $data['jiraPassword'] = $password;
     if ($this->config->write($data) !== false) {
         $output->writeln('Config written to file: ' . $this->config->filePath());
     } else {
         $output->writeln('Nothing written..');
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Mysql();
     $server->setHostname($input->getArgument("host"));
     $server->setUser("provisioning");
     $server->setPassword($this->createPassword());
     $server->setDatabase("provisioning");
     $server->setMode($input->getArgument("mode"));
     $server->setType($input->getArgument("type"));
     $server->setActive(false);
     // convert errors to PDOExceptions
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
     $dsn = sprintf("mysql:host=%s;port=%s;charset=utf8", $server->getHostname(), 3306);
     $pdo = new \PDO($dsn, $input->getArgument("user"), $password, $options);
     $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     $pdo->exec("SET NAMES utf8;");
     $pdo->exec("CREATE USER '{$server->getUser()}'@'%' IDENTIFIED BY '{$server->getPassword()}';");
     $pdo->exec("GRANT CREATE, DROP, GRANT OPTION, LOCK TABLES, REFERENCES, EVENT, ALTER, DELETE, INDEX, INSERT, SELECT, UPDATE, CREATE TEMPORARY TABLES, TRIGGER, CREATE VIEW, SHOW VIEW, ALTER ROUTINE, CREATE ROUTINE, EXECUTE, CREATE USER, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, USAGE ON *.* TO '{$server->getUser()}' WITH GRANT OPTION;");
     $pdo->exec("CREATE DATABASE {$server->getDatabase()} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;");
     // Write to DB
     $entityManager = $this->getProvisioningServer("mysql")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getMySqlServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Please enter app\'s shared secret: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new RuntimeException('Shared secret must be provided');
         }
         return $answer;
     });
     $question->setHidden(true);
     $question->setMaxAttempts(2);
     $sharedSecret = $helper->ask($input, $output, $question);
     $receiptFile = __DIR__ . '/../../../tmp/receipt';
     if (!is_file(realpath($receiptFile))) {
         throw new RuntimeException(sprintf('Create a file with receipt data here %s', $receiptFile));
     }
     $receiptData = file_get_contents($receiptFile);
     if (empty($receiptData)) {
         throw new RuntimeException(sprintf('Put receipt data here %s', $receiptFile));
     }
     $validator = new Validator();
     $validator->setSecret($sharedSecret);
     $validator->setReceiptData($receiptData);
     $response = $validator->validate();
     var_dump($response);
 }
Ejemplo n.º 9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $usernameQuestion = new Question('E-mail: ');
     $usernameQuestion->setValidator(function ($value) {
         if (trim($value) === '') {
             throw new \Exception('E-mail can not be empty');
         }
         if (!Validators::isEmail($value)) {
             throw new \Exception('E-mail is not valid');
         }
         return $value;
     });
     $passwordQuestion = new Question('Password: '******'') {
             throw new \Exception('The password can not be empty');
         }
         return $value;
     });
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $username = $questionHelper->ask($input, $output, $usernameQuestion);
     $password = $questionHelper->ask($input, $output, $passwordQuestion);
     $name = $questionHelper->ask($input, $output, new Question('Name: '));
     $user = $this->userFacade->add($username, $password, $name);
     $output->writeln('User ' . $user->getEmail() . ' was successfully created!');
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $this->getContainer()->getParameter('installed')) {
         throw new ApplicationInstalledException();
     }
     $currencies = Intl::getCurrencyBundle()->getCurrencyNames();
     $locales = Intl::getLocaleBundle()->getLocaleNames();
     $localeQuestion = new Question('<question>Please enter a locale:</question> ');
     $localeQuestion->setAutocompleterValues($locales);
     $currencyQuestion = new Question('<question>Please enter a currency:</question> ');
     $currencyQuestion->setAutocompleterValues($currencies);
     $passwordQuestion = new Question('<question>Please enter a password for the admin account:</question> ');
     $passwordQuestion->setHidden(true);
     $options = array('database-user' => new Question('<question>Please enter your database user name:</question> '), 'admin-username' => new Question('<question>Please enter a username for the admin account:</question> '), 'admin-password' => $passwordQuestion, 'admin-email' => new Question('<question>Please enter an email address for the admin account:</question> '), 'locale' => $localeQuestion, 'currency' => $currencyQuestion);
     /** @var QuestionHelper $dialog */
     $dialog = $this->getHelper('question');
     /** @var Question $question */
     foreach ($options as $option => $question) {
         if (null === $input->getOption($option)) {
             $value = null;
             while (empty($value)) {
                 $value = $dialog->ask($input, $output, $question);
                 if ($values = $question->getAutocompleterValues()) {
                     $value = array_search($value, $values);
                 }
             }
             $input->setOption($option, $value);
         }
     }
 }
Ejemplo n.º 11
0
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $password = getenv('VAULT_PASSWORD');
     $tries = 0;
     while (!$password) {
         $question = new Question('Vault password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $this->vault = new Vault($password, $output);
     // Defaults
     $this->vault->setStoragePath(getcwd() . '/vault');
     $this->vault->setWorkPath(getcwd() . '/secure');
     $this->vault->verify();
     // Load droid.yml
     $filename = $this->getVaultFilename();
     if ($filename && file_exists($filename)) {
         $loader = new JsonLoader();
         $loader->load($vault, $filename);
     } else {
     }
     return parent::doRun($input, $output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Redshift();
     $server->setHostname($input->getArgument("hostname"));
     $server->setConnectionId($input->getArgument("connectionId"));
     $server->setUser("provisioning");
     $server->setPassword($this->createPassword());
     $server->setDatabase("provisioning");
     $server->setMode("active");
     $server->setActive(false);
     // convert errors to PDOExceptions
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_EMULATE_PREPARES => false];
     $dsn = "pgsql:host={$server->getHostname()};port=5439;dbname={$input->getArgument("database")}";
     $pdo = new \PDO($dsn, $input->getArgument("user"), $password, $options);
     $pdo->exec("CREATE USER {$server->getUser()} CREATEUSER PASSWORD '{$server->getPassword()}';");
     $pdo->exec("CREATE DATABASE {$server->getDatabase()};");
     $pdo->exec("REVOKE ALL PRIVILEGES ON SCHEMA public FROM PUBLIC;");
     // Write to DB
     $entityManager = $this->getProvisioningServer("redshift")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getRedshiftServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var WardenSetupService $wardenSetupService */
     $wardenSetupService = $this->getContainer()->get('warden_setup');
     /** @var UserProviderService $userProviderService */
     $userProviderService = $this->getContainer()->get('user_provider');
     if ($userProviderService->isSetup() && !$input->getOption('regenerate')) {
         $output->writeln('Warden username and password is already setup - check the README file if you need to regenerate.');
         return;
     }
     $helper = $this->getHelper('question');
     $usernameQuestion = new Question('Please enter the admin username [admin]: ', 'admin');
     $username = $helper->ask($input, $output, $usernameQuestion);
     $passwordQuestion = new Question('Please enter the admin password (minimum of 8 characters): ', '');
     $passwordQuestion->setValidator(function ($value) {
         if (trim($value) == '') {
             throw new \Exception('The password can not be empty');
         }
         if (strlen($value) < 8) {
             throw new \Exception('Password provided is too short - must be minimum of 8 characters');
         }
         return $value;
     });
     $passwordQuestion->setMaxAttempts(3);
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $password = $helper->ask($input, $output, $passwordQuestion);
     $output->writeln(' - Setting up the password file ...');
     $userProviderService->generateLoginFile($username, $password);
     $output->writeln(' - Setting up the CSS file ...');
     $wardenSetupService->generateCSSFile();
     $output->writeln('Warden installation complete.');
 }
Ejemplo n.º 14
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $provider = $this->getContainer()->get('orm.user_provider');
     /** @var User $user */
     $user = $provider->loadUserByUsername($input->getArgument('username'));
     $pw_question = new Question('New password: '******'Username: <info>' . $user->getUsername() . '</info>');
     $output->writeln('Roles:    <info>' . implode(', ', $roles) . '</info>');
     $this->showRoleWarnings($roles, $output);
     if (!$helper->ask($input, $output, new ConfirmationQuestion('Update user? [y/N]: ', false))) {
         return;
     }
     $user->setRoles($roles);
     $provider = $this->getContainer()->get('orm.user_provider');
     $provider->updateUserCredentials($user, $password);
     $output->writeln("User updated");
 }
Ejemplo n.º 15
0
 protected function secret($question)
 {
     $helper = $this->helperSet->get('question');
     $question = new Question("<question>{$question}</question> ");
     $question->setHidden(true)->setHiddenFallback(true);
     return $helper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 16
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $email = $input->getArgument('email');
     $repository = $this->getRepository();
     /* @var $entity User */
     $entity = $repository->createModel(array());
     try {
         $repository->findByUsername($username);
         $output->writeln(sprintf('A user with the username %s already exists.', $username));
         return 1;
     } catch (NotFound $e) {
     }
     $entity->setUsername($username);
     if ($email) {
         try {
             $repository->findByEmail($email);
             $output->writeln(sprintf('A user with the email %s already exists.', $email));
             return 1;
         } catch (NotFound $e) {
         }
         $entity->setEmail($username);
     }
     $questionHelper = new QuestionHelper();
     $question = new Question(sprintf('<question>%s</question>: ', 'Name (not required):'));
     $entity->setName($questionHelper->ask($input, $output, $question));
     $question = new Question(sprintf('<question>%s</question>: ', 'Enter a password:'******'User %s added successfully.', $username));
 }
Ejemplo n.º 17
0
 protected function allServers(Environment $environment, InputInterface $input, OutputInterface $output, \Closure $action)
 {
     //Loop on the servers
     /**
      * @var \Onigoetz\Deployer\Configuration\Server
      */
     foreach ($environment->getServers() as $server) {
         $output->writeln("Deploying on <info>{$server->getHost()}</info>");
         $output->writeln('-------------------------------------------------');
         //Ask server password if needed ?
         if (!($password = $server->getPassword())) {
             $text = "Password for <info>{$server->getUsername()}@{$server->getHost()}</info>:";
             $question = new Question($text, false);
             $question->setHidden(true)->setHiddenFallback(false);
             $password = $this->getHelper('question')->ask($input, $output, $question);
         }
         //Login to server
         $ssh = new Net_SFTP($server->getHost());
         if (!$ssh->login($server->getUsername(), $password)) {
             throw new \Exception("Login failed on host '{$server->getHost()}'");
         }
         $action($ssh);
         $ssh->disconnect();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Redshift();
     $server->setHostname($input->getArgument("host"));
     $server->setConnectionId($input->getArgument("connectionId"));
     $server->setUser($input->getArgument("user"));
     $server->setPassword($password);
     $server->setDatabase($input->getArgument("database"));
     $server->setMode("active");
     $server->setActive(false);
     // Write to DB
     $entityManager = $this->getProvisioningServer("redshift")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getRedshiftServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 19
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument("login");
     $helper = $this->getHelper('question');
     $question = new Question("Unix password for « {$login} » : ");
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $input->getArgument("password") ? $input->getArgument("password") : $helper->ask($input, $output, $question);
     $blih = new Blih($login, $password);
     $blihRepositoriesResponse = $blih->repository()->all();
     if ($blihRepositoriesResponse->code == 200) {
         $user = $this->getUserOrCreateIt($login);
         $repositoryNames = array_keys(get_object_vars($blihRepositoriesResponse->body->repositories));
         foreach ($repositoryNames as $repositoryName) {
             $output->writeln("> Repository « {$login}/{$repositoryName} »");
             $repository = $this->getRepoOrCreateIt($user, $repositoryName);
             $aclResponse = $blih->repository($repositoryName)->acl()->get();
             if ($aclResponse->code == 200) {
                 $acls = get_object_vars($aclResponse->body);
                 foreach ($acls as $aclLogin => $acl) {
                     $output->writeln("  ACL for « {$aclLogin} »: {$acl}");
                     $aclUser = $this->getUserOrCreateIt($aclLogin);
                     $repositoryACL = $this->getACLOrCreateIt($aclUser, $repository);
                     $repositoryACL->setR(strpos($acl, "r") !== false);
                     $repositoryACL->setW(strpos($acl, "w") !== false);
                     $repositoryACL->setA(strpos($acl, "a") !== false);
                     $this->getContainer()->get("doctrine")->getManager()->persist($repositoryACL);
                 }
             }
             $output->writeln("");
             $this->getContainer()->get("doctrine")->getManager()->persist($repository);
             $this->getContainer()->get("doctrine")->getManager()->flush();
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * Prompt user to fill in a value
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param $label    string          The description of the value
  * @param $default  string|array    The default value. If array given, question will be multiple-choice and the first item will be default. Can also be empty.
  * @param bool $required
  * @param bool $hidden  Hide user input (useful for passwords)
  *
  * @return string   Answer
  */
 protected function _ask(InputInterface $input, OutputInterface $output, $label, $default = '', $required = false, $hidden = false)
 {
     $helper = $this->getHelper('question');
     $text = $label;
     if (is_array($default)) {
         $defaultValue = $default[0];
     } else {
         $defaultValue = $default;
     }
     if (!empty($defaultValue)) {
         $text .= ' [default: <info>' . $defaultValue . '</info>]';
     }
     $text .= ': ';
     if (is_array($default)) {
         $question = new Question\ChoiceQuestion($text, $default, 0);
     } else {
         $question = new Question\Question($text, $default);
     }
     if ($hidden === true) {
         $question->setHidden(true);
     }
     $answer = $helper->ask($input, $output, $question);
     if ($required && empty($answer)) {
         return $this->_ask($input, $output, $label, $default, $hidden);
     }
     return $answer;
 }
Ejemplo n.º 21
0
 /**
  * {@inheritDoc}
  */
 public function getPassword($host, $user)
 {
     $askMessage = sprintf('[%s@%s] Password:', $user, $host);
     $questionHelper = $this->createQuestionHelper();
     $question = new Question($askMessage);
     $question->setHidden(true);
     return $questionHelper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 22
0
 private function askForPassword()
 {
     $helper = $this->getHelper('question');
     $question = new Question('What is the new user\'s password: ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     return $helper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 23
0
 /**
  * Ask the user the given secret question.
  *
  * @param  string  $question
  * @return string
  */
 public function secret($question)
 {
     $question = '<comment>' . $question . '</comment> ';
     $question = new Question($question);
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     return $this->getHelperSet()->get('question')->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $dialog */
     $dialog = $this->getHelperSet()->get('question');
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $output->writeln("");
     $usernameQuestion = new Question(" Enter username [admin]: ", "admin");
     $username = $dialog->ask($input, $output, $usernameQuestion);
     $passwordQuestion = new Question(" Enter password: "******"");
         $errorMessages = ['Error!', 'Please enter not blank password!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         $password = $dialog->ask($input, $output, $passwordQuestion);
         $output->writeln("");
     }
     if (!$password) {
         $output->writeln("");
         $errorMessages = ['Error!', 'If password is blank then goodbye!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         $output->writeln("");
         return;
     }
     $output->writeln("");
     $output->writeln('<info>  Summary information:</>');
     $table = new Table($output);
     $table->setHeaders(['Username'])->setRows([[$username]]);
     $table->render();
     $output->writeln("");
     $question = new ConfirmationQuestion("it's ok? [y/N]: ", false);
     if (!$dialog->ask($input, $output, $question)) {
         $errorMessages = ['Goodbye!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         return;
     }
     /** @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine')->getManager();
     /** @var UserPasswordEncoder $encoder */
     $encoder = $this->getContainer()->get('security.password_encoder');
     if ($em->getRepository('AppBundle:User')->findBy(['username' => $username])) {
         $errorMessages = ['User are exist with input email!!!!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         return;
     }
     $user = new User();
     $user->setUsername($username)->setPassword($encoder->encodePassword($user, $password))->setRoles($user::ROLE_ADMIN_USER);
     $em->persist($user);
     $em->flush();
     $output->writeln('<bg=green>Well done! Admin was created.</>');
 }
Ejemplo n.º 25
0
 /**
  * Asks a question with the given label and hides the input.
  *
  * @param string          $label
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return string
  */
 private function askForPassword($label, InputInterface $input, OutputInterface $output)
 {
     $question = new Question($label);
     $question->setHidden(true);
     $question->setMaxAttempts(3);
     /** @var QuestionHelper $helper */
     $helper = $this->getHelper('question');
     return $helper->ask($input, $output, $question);
 }
Ejemplo n.º 26
0
 /**
  * @param $message
  * @return string
  */
 public function askHiddenResponse($message)
 {
     $this->clearLine();
     $this->output->writeln("\n");
     $question = new Question('<question>' . $message . '</question> ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $var = $this->dialog->ask($this->input, $this->output, $question);
     return $var;
 }
 protected function configureAccount(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Your email address: ');
     $question->setValidator(function ($answer) {
         if (empty($answer) || !filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \RunTimeException('Please provide a valid email address.');
         }
         return $answer;
     });
     $question->setMaxAttempts(5);
     $email = $helper->ask($input, $output, $question);
     $userExists = true;
     if (!$userExists) {
         $createAccountText = "\nThis email address is not associated with a Platform.sh account. \n";
         $createAccountText .= 'Would you like to create a new account?';
         $createAccount = $helper->confirm($createAccountText, $input, $output);
         if ($createAccount) {
             // @todo
         } else {
             // Start from the beginning.
             $this->configureAccount($input, $output);
             return;
         }
     }
     $pendingInvitation = false;
     if ($pendingInvitation) {
         $resendInviteText = "\nThis email address is associated with a Platform.sh account, \n";
         $resendInviteText .= "but you haven't verified your email address yet. \n";
         $resendInviteText .= "Please click on the link in the email we sent you. \n";
         $resendInviteText .= "Do you want us to send you the email again?";
         $resendInvite = $helper->confirm($resendInviteText, $input, $output, false);
         if ($resendInvite) {
             // @todo
         }
         return;
     }
     $question = new Question('Your password: '******'') {
             throw new \RuntimeException('The password cannot be empty');
         }
         return $answer;
     });
     $question->setHidden(true);
     $question->setMaxAttempts(5);
     $password = $helper->ask($input, $output, $question);
     try {
         $this->authenticateUser($email, $password);
     } catch (\InvalidArgumentException $e) {
         $output->writeln("\n<error>Login failed. Please check your credentials.</error>\n");
         $output->writeln("Forgot your password? Visit: <comment>https://marketplace.commerceguys.com/user/password</comment>\n");
         $this->configureAccount($input, $output);
     }
 }
Ejemplo n.º 28
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getArgument('username') && null !== $input->getArgument('password') && null !== $input->getArgument('email')) {
         return;
     }
     // multi-line messages can be displayed this way...
     $output->writeln('');
     $output->writeln('Add User Command Interactive Wizard');
     $output->writeln('-----------------------------------');
     // ...but you can also pass an array of strings to the writeln() method
     $output->writeln(array('', 'If you prefer to not use this interactive wizard, provide the', 'arguments required by this command as follows:', '', ' $ php app/console app:add-user username password email@example.com --isAdmin', ''));
     $output->writeln(array('', 'Now we\'ll ask you for the value of all the missing command arguments.', ''));
     // See http://symfony.com/doc/current/components/console/helpers/questionhelper.html
     $console = $this->getHelper('question');
     // Ask for the username if it's not defined
     $username = $input->getArgument('username');
     if (null === $username) {
         $question = new Question(' > <info>Username</info>: ');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('The username cannot be empty');
             }
             return $answer;
         });
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $username = $console->ask($input, $output, $question);
         $input->setArgument('username', $username);
     } else {
         $output->writeln(' > <info>Username</info>: ' . $username);
     }
     // Ask for the password if it's not defined
     $password = $input->getArgument('password');
     if (null === $password) {
         $question = new Question(' > <info>Password</info> (your type will be hidden): ');
         $question->setValidator(array($this, 'passwordValidator'));
         $question->setHidden(true);
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $password = $console->ask($input, $output, $question);
         $input->setArgument('password', $password);
     } else {
         $output->writeln(' > <info>Password</info>: ' . str_repeat('*', strlen($password)));
     }
     // Ask for the email if it's not defined
     $email = $input->getArgument('email');
     if (null === $email) {
         $question = new Question(' > <info>Email</info>: ');
         $question->setValidator(array($this, 'emailValidator'));
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $email = $console->ask($input, $output, $question);
         $input->setArgument('email', $email);
     } else {
         $output->writeln(' > <info>Email</info>: ' . $email);
     }
 }
Ejemplo n.º 29
0
 protected function requestSlackCredentials(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $output->writeln('<info>Please sign in to Slack to continue. Your username and password are not stored.</info>');
     $emailQuestion = new Question('Email: ');
     $email = $helper->ask($input, $output, $emailQuestion);
     $passwordQuestion = new Question('Password: ');
     $passwordQuestion->setHidden(true);
     $passwordQuestion->setHiddenFallback(false);
     $password = $helper->ask($input, $output, $passwordQuestion);
     return array($email, $password);
 }
Ejemplo n.º 30
0
 /**
  * Asks a question and validates the response.
  *
  * @param string $question
  * @param array $choices
  * @param callback $validator
  * @param mixed $default
  * @param bool $secret
  *
  * @return string
  */
 public function askAndValidate($question, array $choices, $validator, $default = null, $secret = false)
 {
     $question = new Question($question, $default);
     if ($secret) {
         $question->setHidden(true);
     }
     if (count($choices)) {
         $question->setAutocompleterValues($choices);
     }
     $question->setValidator($validator);
     return $this->getOutput()->askQuestion($question);
 }