feat: use default admin credentials during setup

This commit is contained in:
Phan An 2021-01-23 19:58:08 +01:00
parent 7dad6aebf0
commit 4432ad6c21
4 changed files with 17 additions and 45 deletions

View file

@ -17,13 +17,6 @@ DB_PASSWORD=SoSecureMuchWow
# A random 32-char string. You can leave this empty if use php artisan koel:init.
APP_KEY=
# Credentials and other info to be used when Koel is installed in non-interactive mode
# (php artisan koel:init --no-interaction)
# By default (interactive mode), Koel will still prompt for these information during installation,
# but provide the values here as the defaults (except ADMIN_PASSWORD, for security reason).
ADMIN_NAME="Koel Admin"
ADMIN_EMAIL=admin@koel.com
ADMIN_PASSWORD=SoSecureMuchWow
# The ABSOLUTE path to your media. This value can always be changed later via the web interface.
MEDIA_PATH=

View file

@ -19,6 +19,10 @@ class InitCommand extends Command
{
use AskForPassword;
private const DEFAULT_ADMIN_NAME = 'Koel';
private const DEFAULT_ADMIN_EMAIL = 'admin@koel.dev';
private const DEFAULT_ADMIN_PASSWORD = 'KoelIsCool';
protected $signature = 'koel:init {--no-assets}';
protected $description = 'Install or upgrade Koel';
@ -28,6 +32,7 @@ class InitCommand extends Command
private $hash;
private $db;
private $settingRepository;
private $adminSeeded = false;
public function __construct(
MediaCacheService $mediaCacheService,
@ -74,6 +79,12 @@ class InitCommand extends Command
$this->comment(PHP_EOL . '🎆 Success! Koel can now be run from localhost with `php artisan serve`.');
if ($this->adminSeeded) {
$this->comment(
sprintf('Log in with email %s and password %s', self::DEFAULT_ADMIN_EMAIL, self::DEFAULT_ADMIN_PASSWORD)
);
}
if (Setting::get('media_path')) {
$this->comment('You can also scan for media with `php artisan koel:sync`.');
}
@ -151,16 +162,16 @@ class InitCommand extends Command
private function setUpAdminAccount(): void
{
$this->info("Let's create the admin account.");
[$name, $email, $password] = $this->gatherAdminAccountCredentials();
$this->info("Creating default admin account");
User::create([
'name' => $name,
'email' => $email,
'password' => $this->hash->make($password),
'name' => self::DEFAULT_ADMIN_NAME,
'email' => self::DEFAULT_ADMIN_EMAIL,
'password' => $this->hash->make(self::DEFAULT_ADMIN_PASSWORD),
'is_admin' => true,
]);
$this->adminSeeded = true;
}
private function maybeSetMediaPath(): void
@ -270,20 +281,6 @@ class InitCommand extends Command
$runOkOrThrow('yarn build --colors');
}
/** @return array<string> */
private function gatherAdminAccountCredentials(): array
{
if ($this->inNoInteractionMode()) {
return [config('koel.admin.name'), config('koel.admin.email'), config('koel.admin.password')];
}
$name = $this->ask('Your name', config('koel.admin.name'));
$email = $this->ask('Your email address', config('koel.admin.email'));
$password = $this->askForPassword();
return [$name, $email, $password];
}
private function isValidMediaPath(string $path): bool
{
return is_dir($path) && is_readable($path);

View file

@ -1,21 +1,6 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Admin Credentials
|--------------------------------------------------------------------------
|
| When running `php artisan koel:init` the admin is set using the .env
|
*/
'admin' => [
'name' => env('ADMIN_NAME'),
'email' => env('ADMIN_EMAIL'),
'password' => env('ADMIN_PASSWORD'),
],
'media_path' => env('MEDIA_PATH'),
// The *relative* path to the directory to store album covers and thumbnails, *with* a trailing slash.

View file

@ -42,9 +42,6 @@
<env name="LASTFM_API_KEY" value="foo"/>
<env name="LASTFM_API_SECRET" value="bar"/>
<env name="YOUTUBE_API_KEY" value="foo"/>
<env name="ADMIN_EMAIL" value="koel@example.com"/>
<env name="ADMIN_NAME" value="Koel"/>
<env name="ADMIN_PASSWORD" value="SoSecureK0el"/>
<env name="BROADCAST_DRIVER" value="log"/>
<env name="CACHE_MEDIA" value="true"/>
<ini name="memory_limit" value="512M"/>