Initial commit
This commit is contained in:
42
bin/manage.php
Normal file
42
bin/manage.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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);
|
||||
Reference in New Issue
Block a user