Merge pull request #2291 from CachetHQ/add-user-cli

Add user on cachet install command
This commit is contained in:
James Brooks
2019-02-02 12:27:12 +00:00
committed by GitHub
+44 -1
View File
@@ -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;
/**
@@ -70,6 +72,7 @@ class InstallCommand extends Command
$this->configureDrivers();
$this->configureMail();
$this->configureCachet();
$this->configureUser();
}
$this->line('Installing Cachet...');
@@ -313,9 +316,11 @@ class InstallCommand extends Command
/**
* 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?')) {
@@ -332,6 +337,33 @@ class InstallCommand extends Command
}
}
/**
* 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.
*
@@ -372,6 +404,17 @@ class InstallCommand extends Command
$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.
*