Skip to content

Commit

Permalink
fix: disable registration after creating the root user
Browse files Browse the repository at this point in the history
  • Loading branch information
peaklabs-dev committed Jan 16, 2025
1 parent b6633f0 commit 3927e48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ APP_ID=
APP_NAME=Coolify
APP_KEY=

ROOT_USER_NAME=
ROOT_USER_EMAIL=
ROOT_USER_PASSWORD=

DB_USERNAME=coolify
DB_PASSWORD=

Expand All @@ -14,3 +10,7 @@ REDIS_PASSWORD=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

ROOT_USERNAME=
ROOT_USER_EMAIL=
ROOT_USER_PASSWORD=
5 changes: 3 additions & 2 deletions database/seeders/ProductionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ public function run(): void
]);
}
}
// Seed root user first
$this->call(RootUserSeeder::class);

if (InstanceSettings::find(0) == null) {
InstanceSettings::create([
'id' => 0,
]);
}

$this->call(RootUserSeeder::class);

if (GithubApp::find(0) == null) {
GithubApp::create([
'id' => 0,
Expand Down
9 changes: 8 additions & 1 deletion database/seeders/RootUserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

use App\Models\InstanceSettings;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
Expand All @@ -10,7 +11,6 @@ class RootUserSeeder extends Seeder
{
public function run(): void
{
// Only seed if we have the required environment variables
if (env('ROOT_USER_EMAIL') && env('ROOT_USER_PASSWORD')) {
User::updateOrCreate(
['id' => 0],
Expand All @@ -20,7 +20,14 @@ public function run(): void
'password' => Hash::make(env('ROOT_USER_PASSWORD')),
]
);

InstanceSettings::updateOrCreate(
['id' => 0],
['is_registration_enabled' => false]
);

echo " Root user created/updated successfully.\n";
echo " Registration has been disabled.\n";
} else {
echo " Warning: ROOT_USER_EMAIL and ROOT_USER_PASSWORD environment variables are required for root user creation.\n";
}
Expand Down

0 comments on commit 3927e48

Please sign in to comment.