Migrating install and create-admin console commands to use userservice
This commit is contained in:
parent
06ccdd1937
commit
f24f5c0a45
|
@ -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;
|
||||
|
|
|
@ -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('<info>User account created!</info>');
|
||||
} catch (\Exception $ex) {
|
||||
|
|
Loading…
Reference in a new issue