public function askAuth() { $dialog = new DialogHelper(); self::$user = $dialog->ask($this->getOutput(), "<question>GitHub User</question> "); self::$pass = $dialog->askHiddenResponse($this->getOutput(), " <question>Password</question> "); return $this; }
/** * Create DbService instance based on CLI options, prompt for pass * @param InputInterface $input * @param OutputInterface $output * @return DbService */ private function getDbService(InputInterface $input, OutputInterface $output) { $base = $input->getOption('base'); if (!$base) { $output->writeln('<error>Missing base DB name</error>'); return null; } $this->arguments['base'] = $base; $this->arguments['host'] = $input->getOption('host'); $this->arguments['username'] = $input->getOption('username'); $this->arguments['file'] = $input->getOption('file'); $this->arguments['password'] = (string) $this->dialog->askHiddenResponse($output, '<question>Please enter the DB password (default "")</question>', $this->arguments['password']); $target = $input->getOption('target'); $schemaFile = null; if (!$target) { $target = 'compare_' . date('YmdHis'); $output->writeln(sprintf('<info>Missing target DB name - creating schema %s</info>', $target)); $schemaFile = $this->dialog->ask($output, '<question>File to create base schema</question>', null); if (!$schemaFile || !file_exists($schemaFile)) { $output->writeln(sprintf('<error>Invalid schema file: %s</error>', $schemaFile)); return null; } } $this->arguments['target'] = $target; $service = new DbService($this->arguments['host'], $this->arguments['username'], $this->arguments['password'], $this->arguments['base'], $this->arguments['target']); $this->dropSchema = $schemaFile !== null; //ensure schemas exist, create target schema if required $service->checkSchemas($this->dropSchema); if ($schemaFile) { $service->loadTargetSchema($schemaFile); } return $service; }
public function testAskHiddenResponse() { if (defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('This test is not supported on Windows'); } $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("8AM\n")); $this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?')); }
/** * Create DbService instance based on CLI options, prompt for pass * @param InputInterface $input * @param OutputInterface $output * @return DbService */ private function getDbService(InputInterface $input, OutputInterface $output) { $base = $input->getOption('base'); if (!$base) { $output->writeln('<error>Missing base DB name</error>'); return null; } $target = $input->getOption('target'); if (!$target) { $output->writeln('<error>Missing target DB name</error>'); return null; } $host = $input->getOption('host'); $user = $input->getOption('username'); $pass = (string) $this->dialog->askHiddenResponse($output, '<question>Please enter the DB password (default "")</question>', false); return new DbService($host, $user, $pass, $base, $target); }
/** * @group tty */ public function testAskHiddenResponse() { if ('\\' === DIRECTORY_SEPARATOR) { $this->markTestSkipped('This test is not supported on Windows'); } $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("8AM\n")); $this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?')); }
/** * @param OutputInterface $output * @param DialogHelper $dialog */ protected function createAdminUser(OutputInterface $output, DialogHelper $dialog) { // Try to create a user account: $adminEmail = $dialog->askAndValidate($output, 'Your email address: ', function ($answer) { if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) { throw new Exception('Must be a valid email address.'); } return $answer; }, false); $adminPass = $dialog->askHiddenResponse($output, 'Enter your desired admin password: '******'Enter your name: '); try { $user = new User(); $user->setEmail($adminEmail); $user->setName($adminName); $user->setIsAdmin(1); $user->setHash(password_hash($adminPass, PASSWORD_DEFAULT)); $this->reloadConfig(); $store = Factory::getStore('User'); $store->save($user); $output->writeln('<info>User account created!</info>'); } catch (\Exception $ex) { $output->writeln('<error>PHPCI failed to create your admin account.</error>'); $output->writeln('<error>' . $ex->getMessage() . '</error>'); die; } }
private function getCredentials(InputInterface $input, OutputInterface $output, DialogHelper $dialog) { $email = $password = null; if (!$input->getOption('email') && !$input->getOption('password')) { $output->writeln("\n<info>--- Account Informations ---</info>\n"); do { $email = $dialog->ask($output, 'Please provide a valid e-mail address : '); } while (!\Swift_Validate::email($email)); do { $password = $dialog->askHiddenResponse($output, 'Please provide a password (hidden, 6 character min) : '); } while (strlen($password) < 6); $output->writeln("\n\t<info>Email / Password successfully set</info>\n"); } elseif ($input->getOption('email') && $input->getOption('password')) { if (!\Swift_Validate::email($input->getOption('email'))) { throw new \RuntimeException('Invalid email addess'); } $email = $input->getOption('email'); $password = $input->getOption('password'); } else { throw new \RuntimeException('You have to provide both email and password'); } return [$email, $password]; }
/** * @inheritdoc */ public function askHiddenResponse($question, $fallback = true) { return parent::askHiddenResponse($this->output, $this->formatQuestion($question), $fallback); }
/** * @group tty */ public function testAskHiddenResponseOnErrorOutput() { if ('\\' === DIRECTORY_SEPARATOR) { $this->markTestSkipped('This test is not supported on Windows'); } $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("8AM\n")); $this->assertEquals('8AM', $dialog->askHiddenResponse($output = $this->getConsoleOutput($this->getOutputStream()), 'What time is it?')); rewind($output->getErrorOutput()->getStream()); $this->assertContains('What time is it?', stream_get_contents($output->getErrorOutput()->getStream())); }