56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Account;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class ImportUsersCommand extends Command
|
|
{
|
|
protected $signature = 'import:users {file}';
|
|
protected $description = 'Import users from a text file';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$filePath = $this->argument('file');
|
|
|
|
if (!file_exists($filePath)) {
|
|
$this->error("Le fichier spécifié n'existe pas.");
|
|
return 1;
|
|
}
|
|
|
|
$file = fopen($filePath, 'r');
|
|
|
|
while (($line = fgets($file)) !== false) {
|
|
$data = explode(':', trim($line));
|
|
|
|
if (count($data) < 5) {
|
|
$this->error("Format incorrect dans le fichier.");
|
|
continue;
|
|
}
|
|
|
|
[$username, $password, $email, $emailPassword, $token] = $data;
|
|
|
|
Account::create([
|
|
'name' => $username,
|
|
'password' => $password,
|
|
'rambler_email' => $email,
|
|
'rambler_password' => $emailPassword,
|
|
'auth_token' => $token,
|
|
]);
|
|
|
|
$this->info("Utilisateur {$username} importé avec succès.");
|
|
}
|
|
|
|
fclose($file);
|
|
|
|
$this->info("Importation terminée.");
|
|
return 0;
|
|
}
|
|
} |