diff --git a/src/flextype/core/Console/Commands/Utils/CreateTokenCommand.php b/src/flextype/core/Console/Commands/Utils/CreateTokenCommand.php new file mode 100644 index 00000000..16b6e89a --- /dev/null +++ b/src/flextype/core/Console/Commands/Utils/CreateTokenCommand.php @@ -0,0 +1,60 @@ +setName('utils:create-token'); + $this->setDescription('Create a new unique token.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $token = generateToken(); + $access_token = generateToken(); + $hashed_access_token = generateTokenHash($access_token); + + filesystem()->directory(PATH['project'] . '/entries/tokens')->ensureExists(); + + if (entries()->create('tokens/' . $token, ['hashed_access_token' => $hashed_access_token])) { + $output->write( + renderToString( + div('Success: Token [b]' . $token . '[/b] with secret access token [b]' . $access_token . '[/b] created.', + 'bg-success px-2 py-1') + ) + ); + return Command::SUCCESS; + } else { + $output->write( + renderToString( + div('Failure: Token wasn\'t created.', + 'bg-danger px-2 py-1') + ) + ); + return Command::FAILURE; + } + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsole.php b/src/flextype/core/Console/FlextypeConsole.php index f3556170..5082167d 100644 --- a/src/flextype/core/Console/FlextypeConsole.php +++ b/src/flextype/core/Console/FlextypeConsole.php @@ -35,6 +35,7 @@ use Flextype\Console\Commands\Cache\CacheHasCommand; use Flextype\Console\Commands\Utils\GenerateTokenCommand; use Flextype\Console\Commands\Utils\GenerateTokenHashCommand; use Flextype\Console\Commands\Utils\VerifyTokenHashCommand; +use Flextype\Console\Commands\Utils\CreateTokenCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -61,7 +62,8 @@ class FlextypeConsole extends ConsoleApplication console()->add(new GenerateTokenCommand()); console()->add(new GenerateTokenHashCommand()); console()->add(new VerifyTokenHashCommand()); - + console()->add(new CreateTokenCommand()); + parent::run(); } } \ No newline at end of file