mirror of https://github.com/pixelfed/pixelfed
Create SeedDevUsers.php
parent
601b13dbe7
commit
16b5ffff10
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SeedDevUsers extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'seed:devusers';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Seed dev users (admin + regular) with random passwords';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$users = [
|
||||
[
|
||||
'name' => 'Admin User',
|
||||
'username' => 'admin',
|
||||
'email' => 'admin@example.com',
|
||||
'is_admin' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'Test User',
|
||||
'username' => 'user',
|
||||
'email' => 'user@example.com',
|
||||
'is_admin' => false,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($users as $data) {
|
||||
if (User::whereUsername($data['username'])->exists()) {
|
||||
$this->warn("User '{$data['username']}' already exists, skipping.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$password = Str::random(16);
|
||||
|
||||
$user = User::factory()->create([
|
||||
'name' => $data['name'],
|
||||
'username' => $data['username'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($password),
|
||||
'is_admin' => $data['is_admin'],
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$role = $data['is_admin'] ? 'admin' : 'user';
|
||||
$this->info("Created {$role}: {$data['username']} / {$data['email']} — password: {$password}");
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->info('Done! Save these passwords — they are generated randomly each run.');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue