1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(console): add VerifyTokenHashCommand, GenerateTokenHashCommand, GenerateTokenCommand #543

This commit is contained in:
Awilum
2021-09-22 13:53:47 +03:00
parent 91e22739bf
commit b9525908c9
4 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Console\Commands\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class GenerateTokenCommand extends Command
{
protected function configure(): void
{
$this->setName('utils:generate-token');
$this->setDescription('Generate token.');
$this->addArgument('length', InputArgument::OPTIONAL, 'Token string length.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(generateToken($input->getArgument('length') ?? 16));
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Console\Commands\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class GenerateTokenHashCommand extends Command
{
protected function configure(): void
{
$this->setName('utils:generate-token-hash');
$this->setDescription('Generate token hash.');
$this->addArgument('token', InputArgument::REQUIRED, 'Token string.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(generateTokenHash($input->getArgument('token')));
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Console\Commands\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Style\SymfonyStyle;
class VerifyTokenHashCommand extends Command
{
protected function configure(): void
{
$this->setName('utils:verify-token-hash');
$this->setDescription('Verify token hash.');
$this->addArgument('token', InputArgument::REQUIRED, 'Token.');
$this->addArgument('token-hash', InputArgument::REQUIRED, 'Token hash.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
if (verrifyTokenHash($input->getArgument('token'), $input->getArgument('token-hash') )) {
$io->success('Token ' . $input->getArgument('token') . ' is verified');
return Command::SUCCESS;
} else {
$io->error('Token ' . $input->getArgument('token') . ' isn\'t verified');
return Command::FAILURE;
}
}
}

View File

@@ -25,6 +25,9 @@ use Flextype\Console\Commands\Cache\CacheSetMultipleCommand;
use Flextype\Console\Commands\Cache\CacheDeleteMultipleCommand;
use Flextype\Console\Commands\Cache\CacheClearCommand;
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 Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -48,6 +51,9 @@ class FlextypeConsoleApplication extends ConsoleApplication
console()->add(new CacheDeleteCommand());
console()->add(new CacheClearCommand());
console()->add(new CacheHasCommand());
console()->add(new GenerateTokenCommand());
console()->add(new GenerateTokenHashCommand());
console()->add(new VerifyTokenHashCommand());
parent::run();
}