Skip to content

Commit

Permalink
Merge pull request #2291 from CachetHQ/add-user-cli
Browse files Browse the repository at this point in the history
Add user on cachet install command
  • Loading branch information
jbrooksuk committed Feb 2, 2019
2 parents a0f9d9f + ba5d865 commit 785c6a5
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace CachetHQ\Cachet\Console\Commands;

use CachetHQ\Cachet\Models\User;
use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Contracts\Events\Dispatcher;

/**
Expand Down Expand Up @@ -70,6 +72,7 @@ public function handle()
$this->configureDrivers();
$this->configureMail();
$this->configureCachet();
$this->configureUser();
}

$this->line('Installing Cachet...');
Expand Down Expand Up @@ -313,9 +316,11 @@ protected function configureMail(array $config = [])
/**
* Configure Cachet.
*
* @param array $config
*
* @return void
*/
protected function configureCachet()
protected function configureCachet(array $config = [])
{
$config = [];
if ($this->confirm('Do you wish to use Cachet Beacon?')) {
Expand All @@ -332,6 +337,33 @@ protected function configureCachet()
}
}

/**
* Configure the first user.
*
* @return void
*/
protected function configureUser()
{
if (!$this->confirm('Do you want to create an admin user?')) {
return;
}

// We need to refresh the config to get access to the newly connected database.
$this->getFreshConfiguration();

// Now we need to install the application.
// $this->call('cachet:install');

$user = [
'username' => $this->ask('Please enter your username'),
'email' => $this->ask('Please enter your email'),
'password' => $this->secret('Please enter your password'),
'level' => User::LEVEL_ADMIN,
];

User::create($user);
}

/**
* Configure the redis connection.
*
Expand Down Expand Up @@ -372,6 +404,17 @@ protected function formatConfigsTable(array $config)
$this->table(['Setting', 'Value'], $configRows);
}

/**
* Boot a fresh copy of the application configuration.
*
* @return void
*/
protected function getFreshConfiguration()
{
$app = require $this->laravel->bootstrapPath().'/app.php';
$app->make(Kernel::class)->bootstrap();
}

/**
* Writes to the .env file with given parameters.
*
Expand Down

0 comments on commit 785c6a5

Please sign in to comment.