58 lines
1.5 KiB
Plaintext
Executable File
58 lines
1.5 KiB
Plaintext
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use Domovoy\Services\AuthService;
|
|
use Domovoy\Repositories\UserRepository;
|
|
|
|
$dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
|
$dotenv->safeLoad();
|
|
|
|
$pdo = new PDO(
|
|
sprintf(
|
|
'mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4',
|
|
getenv('DB_HOST') ?: 'db',
|
|
getenv('DB_PORT') ?: 3306,
|
|
getenv('DB_DATABASE') ?: 'domovoy'
|
|
),
|
|
getenv('DB_USERNAME') ?: 'domovoy',
|
|
getenv('DB_PASSWORD') ?: 'domovoy',
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
]
|
|
);
|
|
|
|
$authService = new AuthService(new UserRepository($pdo));
|
|
|
|
$command = $argv[1] ?? 'help';
|
|
|
|
switch ($command) {
|
|
case 'setup:user':
|
|
if ($argv[2] ?? false) {
|
|
// CLI mode: bin/console setup:user username password
|
|
$username = $argv[2];
|
|
$password = $argv[3] ?? 'password123';
|
|
} else {
|
|
// Interactive mode
|
|
echo "Username: ";
|
|
$username = trim(fgets(STDIN));
|
|
echo "Password: ";
|
|
$password = trim(fgets(STDIN));
|
|
}
|
|
|
|
$user = $authService->createUser($username, $password);
|
|
echo "User '{$user->username}' created successfully.\n";
|
|
break;
|
|
|
|
case 'help':
|
|
default:
|
|
echo "Domovoy CLI\n\n";
|
|
echo "Commands:\n";
|
|
echo " setup:user [username] [password] Create first admin user\n";
|
|
echo " help Show this help\n";
|
|
break;
|
|
}
|