From da4c77c690ded640979710a2350282569c29dd45 Mon Sep 17 00:00:00 2001 From: Dmitrii Zolotov Date: Sun, 13 Mar 2016 02:05:03 +0600 Subject: [PATCH] Register user command (with service modifications) --- PHPCI/Command/RegisterUserCommand.php | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 PHPCI/Command/RegisterUserCommand.php diff --git a/PHPCI/Command/RegisterUserCommand.php b/PHPCI/Command/RegisterUserCommand.php new file mode 100644 index 00000000..15c5a3e4 --- /dev/null +++ b/PHPCI/Command/RegisterUserCommand.php @@ -0,0 +1,87 @@ +userStore = $userStore; + } + + protected function configure() + { + $this + ->setName('phpci:register-user') + ->setDescription(Lang::get('register_user')); + } + + /** + * Creates an admin user in the existing PHPCI database + * + * {@inheritDoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $userService = new UserService($this->userStore); + + /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ + $dialog = $this->getHelperSet()->get('dialog'); + + // Function to validate mail address. + $mailValidator = function ($answer) { + if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) { + throw new \InvalidArgumentException(Lang::get('must_be_valid_email')); + } + + return $answer; + }; + + $id = $dialog->ask($output, Lang::get('enter_id')); + $pass = $dialog->askHiddenResponse($output, Lang::get('enter_password')); + $email = $dialog->askAndValidate($output, Lang::get('enter_email'), $mailValidator, false); + $providerKey = $dialog->ask($output, Lang::get('enter_providerkey')); + $providerData = $dialog->ask($output, Lang::get('enter_providerdata')); + $isAdmin = $dialog->ask($output, Lang::get('enter_isadmin')); + $isAdmin = !empty($isAdmin); + $name = $dialog->ask($output, Lang::get('enter_name')); + + try { + $userService->createUserWithProvider($name, $emailAddress, $id, $password, $providerKey, $providerData, $isAdmin = false); + $output->writeln(Lang::get('user_created')); + } catch (\Exception $e) { + $output->writeln(sprintf('%s', Lang::get('failed_to_create'))); + $output->writeln(sprintf('%s', $e->getMessage())); + } + } +}