feat: make admin email configurable and interactive password seeding
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\enum\UserLevel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -13,12 +14,48 @@ class AdminSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$adminEmail = config('app.admin_email');
|
||||
|
||||
if (! $adminEmail) {
|
||||
$this->command->error('ADMIN_EMAIL not configured in config/app.php or .env file');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if admin user already exists
|
||||
$existingAdmin = User::where('email', $adminEmail)->first();
|
||||
if ($existingAdmin) {
|
||||
$this->command->info("Admin user with email {$adminEmail} already exists");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask for admin password
|
||||
$password = $this->command->secret('Enter admin password (input will be hidden):');
|
||||
|
||||
if (empty($password)) {
|
||||
$this->command->error('Password cannot be empty');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirm password
|
||||
$passwordConfirmation = $this->command->secret('Confirm admin password:');
|
||||
|
||||
if ($password !== $passwordConfirmation) {
|
||||
$this->command->error('Passwords do not match');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
User::query()->create([
|
||||
'name' => 'admin',
|
||||
'email' => 'admin@zemail.me',
|
||||
'password' => Hash::make('password'),
|
||||
'level' => 9,
|
||||
'email' => $adminEmail,
|
||||
'password' => Hash::make($password),
|
||||
'level' => UserLevel::SUPERADMIN,
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$this->command->info("Admin user created successfully with email: {$adminEmail}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user