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

feat(console): improve utils console commands logic

This commit is contained in:
Awilum
2022-04-30 12:11:39 +03:00
parent 0f1a117ce2
commit e6f638f567
3 changed files with 37 additions and 7 deletions

View File

@@ -20,6 +20,8 @@ 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 function Thermage\div;
use function Thermage\renderToString;
class GenerateTokenCommand extends Command
{
@@ -32,7 +34,13 @@ class GenerateTokenCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(generateToken($input->getArgument('length') ?? 16));
$output->write(
renderToString(
div('Success: Token [b]' . generateToken($input->getArgument('length') ?? 16) . '[/b] generated.',
'bg-success px-2 py-1')
)
);
return Command::SUCCESS;
}
}

View File

@@ -20,6 +20,8 @@ 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 function Thermage\div;
use function Thermage\renderToString;
class GenerateTokenHashCommand extends Command
{
@@ -27,12 +29,20 @@ class GenerateTokenHashCommand extends Command
{
$this->setName('utils:generate-token-hash');
$this->setDescription('Generate token hash.');
$this->addArgument('token', InputArgument::REQUIRED, 'Token string.');
$this->addArgument('token', InputArgument::OPTIONAL, 'Token string.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(generateTokenHash($input->getArgument('token')));
$token = $input->getArgument('token') ?? generateToken();
$output->write(
renderToString(
div('Success: Hash [b]' . generateTokenHash($token) . '[/b] for token [b]' . $token . '[/b] generated.',
'bg-success px-2 py-1')
)
);
return Command::SUCCESS;
}
}

View File

@@ -21,6 +21,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Thermage\div;
use function Thermage\renderToString;
class VerifyTokenHashCommand extends Command
{
@@ -34,13 +36,23 @@ class VerifyTokenHashCommand extends Command
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');
$output->write(
renderToString(
div('Success: Token [b]' . $input->getArgument('token') . ' is verified',
'bg-success px-2 py-1')
)
);
return Command::SUCCESS;
} else {
$io->error('Token ' . $input->getArgument('token') . ' isn\'t verified');
$output->write(
renderToString(
div('Failure: Token [b]' . $input->getArgument('token') . ' isn\'t verified',
'bg-success px-2 py-1')
)
);
return Command::FAILURE;
}
}