43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Hpz937\Phpvault\Database;
|
|
use Hpz937\Phpvault\Handler\AuthHandler;
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
|
|
$dotenv->load();
|
|
|
|
$database = new Database();
|
|
$authHandler = new AuthHandler($_ENV['JWT_SECRET_KEY'], $database);
|
|
|
|
$app = new Ahc\Cli\Application('phpvault', '0.0.1');
|
|
|
|
$app->command('create-tables', 'Create database tables', 'ct')
|
|
->action(function() use ($database) {
|
|
$database->createTables();
|
|
echo "Tables created successfully!\n";
|
|
});
|
|
|
|
$app->command('add-user', 'Add a new user', 'au')
|
|
->argument('<username>', 'Username')
|
|
->action(function($username) use ($authHandler) {
|
|
$interactor = new Ahc\Cli\IO\Interactor;
|
|
$passValidator = function ($pass) {
|
|
if (\strlen($pass) < 6) {
|
|
throw new \InvalidArgumentException('Password too short');
|
|
}
|
|
|
|
return $pass;
|
|
};
|
|
$password = $interactor->promptHidden('Password', $passValidator, 2);
|
|
|
|
if ($authHandler->addUser($username, $password)) {
|
|
echo "User added successfully!\n";
|
|
} else {
|
|
echo "Failed to add user\n";
|
|
}
|
|
});
|
|
|
|
$app->handle($argv);
|