fix: RootUserSeeder
- ensure that the existing root user is not overwritten - ensure that the seeder can only be run once - creating the initial root user
This commit is contained in:
@@ -11,22 +11,26 @@ class RootUserSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
if (User::where('id', 0)->exists()) {
|
||||||
|
echo " Root user already exists. Skipping creation.\n";
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (env('ROOT_USER_EMAIL') && env('ROOT_USER_PASSWORD')) {
|
if (env('ROOT_USER_EMAIL') && env('ROOT_USER_PASSWORD')) {
|
||||||
User::updateOrCreate(
|
User::create([
|
||||||
['id' => 0],
|
'id' => 0,
|
||||||
[
|
'name' => env('ROOT_USERNAME', 'Root User'),
|
||||||
'name' => env('ROOT_USER_NAME', 'Root User'),
|
|
||||||
'email' => env('ROOT_USER_EMAIL'),
|
'email' => env('ROOT_USER_EMAIL'),
|
||||||
'password' => Hash::make(env('ROOT_USER_PASSWORD')),
|
'password' => Hash::make(env('ROOT_USER_PASSWORD')),
|
||||||
]
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
InstanceSettings::updateOrCreate(
|
InstanceSettings::updateOrCreate(
|
||||||
['id' => 0],
|
['id' => 0],
|
||||||
['is_registration_enabled' => false]
|
['is_registration_enabled' => false]
|
||||||
);
|
);
|
||||||
|
|
||||||
echo " Root user created/updated successfully.\n";
|
echo " Root user created successfully.\n";
|
||||||
echo " Registration has been disabled.\n";
|
echo " Registration has been disabled.\n";
|
||||||
} else {
|
} else {
|
||||||
echo " Warning: ROOT_USER_EMAIL and ROOT_USER_PASSWORD environment variables are required for root user creation.\n";
|
echo " Warning: ROOT_USER_EMAIL and ROOT_USER_PASSWORD environment variables are required for root user creation.\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user