Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user on cachet install command #2291

Merged
merged 4 commits into from
Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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