From 217d94a8c21e773733f84292999afd4397f4126e Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 23 Jul 2014 15:56:23 +0100 Subject: [PATCH] Migrating install and create-admin console commands to use userservice --- PHPCI/Command/CreateAdminCommand.php | 15 +++++---------- PHPCI/Command/InstallCommand.php | 11 +++-------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/PHPCI/Command/CreateAdminCommand.php b/PHPCI/Command/CreateAdminCommand.php index 30d800b1..fc40c307 100644 --- a/PHPCI/Command/CreateAdminCommand.php +++ b/PHPCI/Command/CreateAdminCommand.php @@ -9,6 +9,7 @@ namespace PHPCI\Command; +use PHPCI\Service\UserService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -37,7 +38,9 @@ class CreateAdminCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - + $userStore = Factory::getStore('User'); + $userService = new UserService($userStore); + require(PHPCI_DIR . 'bootstrap.php'); // Try to create a user account: @@ -51,15 +54,7 @@ class CreateAdminCommand extends Command $adminName = $this->ask('Admin name: '); try { - $user = new \PHPCI\Model\User(); - $user->setEmail($adminEmail); - $user->setName($adminName); - $user->setIsAdmin(1); - $user->setHash(password_hash($adminPass, PASSWORD_DEFAULT)); - - $store = \b8\Store\Factory::getStore('User'); - $store->save($user); - + $userService->createUser($adminName, $adminEmail, $adminPass, 1); print 'User account created!' . PHP_EOL; } catch (\Exception $ex) { print 'There was a problem creating your account. :(' . PHP_EOL; diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php index 43495dc0..e5317261 100644 --- a/PHPCI/Command/InstallCommand.php +++ b/PHPCI/Command/InstallCommand.php @@ -236,16 +236,11 @@ class InstallCommand extends Command $adminName = $dialog->ask($output, '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); + $userStore = Factory::getStore('User'); + $userService = new UserService($userStore); + $userService->createUser($adminName, $adminEmail, $adminPass, 1); $output->writeln('User account created!'); } catch (\Exception $ex) {