diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 9b9a739..ac25184 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -229,21 +229,27 @@ tr.table-primary-light { } } +@media screen and (max-width: 1080px) { + .sidebar-sticky { + overflow-y: auto !important; + } +} + @media screen and (max-width: 770px) { .body { margin-left: 50px; width: calc(100vw - 50px); } + .sidebar-sticky { + width: 50px; + max-width: 100% !important; + } + .sidebar { width: 50px; max-width: 100% !important; - .sidebar-sticky { - width: 50px; - max-width: 100% !important; - } - .nav { padding-left: 0; } diff --git a/core/Command/UserCreateCommand.php b/core/Command/UserCreateCommand.php index 2248210..598bfaf 100644 --- a/core/Command/UserCreateCommand.php +++ b/core/Command/UserCreateCommand.php @@ -7,10 +7,12 @@ use App\Core\Manager\EntityManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface; class UserCreateCommand extends Command { @@ -18,11 +20,16 @@ class UserCreateCommand extends Command protected static $defaultDescription = 'Creates a user'; protected UserFactory $userFactory; protected EntityManager $entityManager; + protected TokenGeneratorInterface $tokenGenerator; - public function __construct(UserFactory $userFactory, EntityManager $entityManager) - { + public function __construct( + UserFactory $userFactory, + EntityManager $entityManager, + TokenGeneratorInterface $tokenGenerator + ) { $this->userFactory = $userFactory; $this->entityManager = $entityManager; + $this->tokenGenerator = $tokenGenerator; parent::__construct(); } @@ -32,6 +39,8 @@ class UserCreateCommand extends Command $this ->setDescription(self::$defaultDescription) ->addArgument('email', InputArgument::OPTIONAL, 'E-mail') + ->addOption('is-admin', null, InputOption::VALUE_NONE, 'Add the admin role') + ->addOption('is-writer', null, InputOption::VALUE_NONE, 'Add the write role') ; } @@ -43,9 +52,7 @@ class UserCreateCommand extends Command $emailQuestion = new Question('E-mail: '); $emailQuestion->setValidator(function ($value) { if (empty($value)) { - throw new \RuntimeException( - 'The email must not be empty.' - ); + throw new \RuntimeException('The email must not be empty.'); } return $value; @@ -53,8 +60,17 @@ class UserCreateCommand extends Command $passwordQuestion = new Question('Password (leave empty to generate a random password): '); $passwordQuestion->setHidden(true); - $isAdminQuestion = new ConfirmationQuestion('Is admin? [y/n] ', false); - $isWriterQuestion = new ConfirmationQuestion('Is writer? [y/n] ', false); + + $isAdminDefault = $input->getOption('is-admin'); + $isWriterDefault = $input->getOption('is-writer'); + + $isAdminQuestionLabel = sprintf('Administrator [%s] ', $isAdminDefault ? 'Y/n' : 'y/N'); + $isWriterQuestionLabel = sprintf('Writer [%s] ', $isWriterDefault ? 'Y/n' : 'y/N'); + + $isAdminQuestion = new ConfirmationQuestion($isAdminQuestionLabel, $isAdminDefault); + $isWriterQuestion = new ConfirmationQuestion($isWriterQuestionLabel, $isWriterDefault); + + $io->section('Authentication'); $email = $input->getArgument('email'); @@ -63,6 +79,18 @@ class UserCreateCommand extends Command } $password = $helper->ask($input, $output, $passwordQuestion); + + $showPassword = empty($password); + + if ($showPassword) { + $password = mb_substr($this->tokenGenerator->generateToken(), 0, 18); + $io->info(sprintf('Password: %s', $password)); + } else { + $io->newLine(); + } + + $io->section('Roles'); + $isAdmin = $helper->ask($input, $output, $isAdminQuestion); $isWriter = $helper->ask($input, $output, $isWriterQuestion); @@ -72,6 +100,7 @@ class UserCreateCommand extends Command $this->entityManager->create($user); + $io->newLine(); $io->success('User created!'); return Command::SUCCESS; diff --git a/core/Factory/UserFactory.php b/core/Factory/UserFactory.php index 9d4d4bc..0218062 100644 --- a/core/Factory/UserFactory.php +++ b/core/Factory/UserFactory.php @@ -16,9 +16,8 @@ class UserFactory implements FactoryInterface protected TokenGeneratorInterface $tokenGenerator; protected UserPasswordEncoderInterface $encoder; - public function __construct(TokenGeneratorInterface $tokenGenerator, UserPasswordEncoderInterface $encoder) + public function __construct(UserPasswordEncoderInterface $encoder) { - $this->tokenGenerator = $tokenGenerator; $this->encoder = $encoder; } @@ -26,14 +25,13 @@ class UserFactory implements FactoryInterface { $entity = new User(); - if (!empty($email)) { + if (null !== $email) { $entity->setEmail($email); } - $entity->setPassword($this->encoder->encodePassword( - $entity, - !empty($password) ? $password : $this->tokenGenerator->generateToken() - )); + if (null !== $email) { + $entity->setPassword($this->encoder->encodePassword($entity, $password)); + } return $entity; } diff --git a/core/Resources/views/site/tree_admin/navigation.html.twig b/core/Resources/views/site/tree_admin/navigation.html.twig index 31efad1..5b16b3c 100644 --- a/core/Resources/views/site/tree_admin/navigation.html.twig +++ b/core/Resources/views/site/tree_admin/navigation.html.twig @@ -125,7 +125,7 @@
-