backports murph-skeleton
This commit is contained in:
parent
d4721d60bf
commit
feec09a727
73
core/Command/UserCreateCommand.php
Normal file
73
core/Command/UserCreateCommand.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Command;
|
||||
|
||||
use App\Core\Factory\UserFactory;
|
||||
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\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class UserCreateCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'murph:user:create';
|
||||
protected static $defaultDescription = 'Creates a user';
|
||||
protected UserFactory $userFactory;
|
||||
protected EntityManager $entityManager;
|
||||
|
||||
public function __construct(UserFactory $userFactory, EntityManager $entityManager)
|
||||
{
|
||||
$this->userFactory = $userFactory;
|
||||
$this->entityManager = $entityManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription(self::$defaultDescription)
|
||||
->addArgument('email', InputArgument::OPTIONAL, 'E-mail')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$helper = $this->getHelper('question');
|
||||
|
||||
$emailQuestion = new Question('E-mail: ');
|
||||
$emailQuestion->setValidator(function ($value) {
|
||||
return !empty($value);
|
||||
});
|
||||
|
||||
$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);
|
||||
|
||||
$email = $input->getArgument('email');
|
||||
|
||||
if (empty($email)) {
|
||||
$email = $helper->ask($input, $output, $emailQuestion);
|
||||
}
|
||||
|
||||
$password = $helper->ask($input, $output, $passwordQuestion);
|
||||
$isAdmin = $helper->ask($input, $output, $isAdminQuestion);
|
||||
$isWriter = $helper->ask($input, $output, $isWriterQuestion);
|
||||
|
||||
$user = $this->userFactory->create($email, $password);
|
||||
$user->setIsAdmin($isAdmin);
|
||||
$user->setIsWriter($isWriter);
|
||||
|
||||
$this->entityManager->create($user);
|
||||
|
||||
$io->success('User created!');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ use App\Core\Factory\Site\MenuFactory;
|
|||
use App\Core\Form\Site\MenuType;
|
||||
use App\Core\Repository\Site\NavigationRepositoryQuery;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
|
@ -18,9 +19,21 @@ class TreeAdminController extends AdminController
|
|||
/**
|
||||
* @Route("/", name="admin_site_tree_index")
|
||||
*/
|
||||
public function index(NavigationRepositoryQuery $navigationQuery): Response
|
||||
public function index(NavigationRepositoryQuery $navigationQuery, Session $session): Response
|
||||
{
|
||||
$navigation = $navigationQuery->create()->findOne();
|
||||
$navigation = null;
|
||||
|
||||
if ($session->has('site_tree_last_navigation')) {
|
||||
$navigation = $navigationQuery->create()
|
||||
->where('.id = :id')
|
||||
->setParameter(':id', (int) $session->get('site_tree_last_navigation'))
|
||||
->findOne()
|
||||
;
|
||||
}
|
||||
|
||||
if (null === $navigation) {
|
||||
$navigation = $navigationQuery->create()->findOne();
|
||||
}
|
||||
|
||||
if (null === $navigation) {
|
||||
$this->addFlash('warning', 'You must add a navigation.');
|
||||
|
@ -39,10 +52,13 @@ class TreeAdminController extends AdminController
|
|||
public function navigation(
|
||||
Navigation $navigation,
|
||||
NavigationRepositoryQuery $navigationQuery,
|
||||
MenuFactory $menuFactory
|
||||
MenuFactory $menuFactory,
|
||||
Session $session
|
||||
): Response {
|
||||
$navigations = $navigationQuery->create()->find();
|
||||
|
||||
$session->set('site_tree_last_navigation', $navigation->getId());
|
||||
|
||||
$forms = [
|
||||
'menu' => $this->createForm(MenuType::class, $menuFactory->create())->createView(),
|
||||
'menus' => [],
|
||||
|
|
|
@ -44,6 +44,11 @@ class Navigation implements EntityInterface
|
|||
*/
|
||||
private $menus;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=10)
|
||||
*/
|
||||
private $locale = 'en';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menus = new ArrayCollection();
|
||||
|
@ -135,4 +140,16 @@ class Navigation implements EntityInterface
|
|||
{
|
||||
return $this->getCode() ? $this->getCode() : 'navigation_'.$this->getId();
|
||||
}
|
||||
|
||||
public function getLocale(): ?string
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function setLocale(string $locale): self
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,17 @@ class UserFactory
|
|||
$this->encoder = $encoder;
|
||||
}
|
||||
|
||||
public function create(): User
|
||||
public function create(?string $email = null, ?string $password = null): User
|
||||
{
|
||||
$entity = new User();
|
||||
|
||||
if (!empty($email)) {
|
||||
$entity->setEmail($email);
|
||||
}
|
||||
|
||||
$entity->setPassword($this->encoder->encodePassword(
|
||||
$entity,
|
||||
$this->tokenGenerator->generateToken()
|
||||
!empty($password) ? $password : $this->tokenGenerator->generateToken()
|
||||
));
|
||||
|
||||
return $entity;
|
||||
|
|
|
@ -8,6 +8,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
|
||||
class NavigationType extends AbstractType
|
||||
{
|
||||
|
@ -54,6 +55,21 @@ class NavigationType extends AbstractType
|
|||
],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add(
|
||||
'locale',
|
||||
TextType::class,
|
||||
[
|
||||
'label' => 'Locale',
|
||||
'required' => true,
|
||||
'attr' => [
|
||||
],
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new Length(['min' => 2, 'max' => 10]),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"This is a test of translation": "Ceci est un test de traduction"
|
||||
"The code is not valid.": "Le code n'est pas valide."
|
||||
"Double authentication enabled.": "Double authentification activée."
|
||||
"Double authentication disabled.": "Double authentification désactivée."
|
||||
|
@ -127,3 +128,4 @@
|
|||
"Anyway": "Peu importe"
|
||||
"Yes": "Oui"
|
||||
"No": "Non"
|
||||
"Locale": "Langue"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="row">
|
||||
<div class="col-12 p-3">
|
||||
<div class="row">
|
||||
{% for item in ['label', 'code', 'domain'] %}
|
||||
{% for item in ['label', 'domain', 'locale', 'code'] %}
|
||||
<div class="col-12">
|
||||
{{ form_row(form[item]) }}
|
||||
</div>
|
||||
|
|
|
@ -32,6 +32,16 @@ class SiteRouteLoader extends Loader
|
|||
$routes = new RouteCollection();
|
||||
$navigations = $this->navigationQuery->find();
|
||||
|
||||
$uniqueness = [];
|
||||
|
||||
foreach ($navigations as $navigation) {
|
||||
if (!isset($uniqueness[$navigation->getDomain()])) {
|
||||
$uniqueness[$navigation->getDomain()] = true;
|
||||
} else {
|
||||
$uniqueness[$navigation->getDomain()] = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($navigations as $navigation) {
|
||||
foreach ($navigation->getMenus() as $menu) {
|
||||
foreach ($menu->getRootNode()->getAllChildren() as $node) {
|
||||
|
@ -51,6 +61,7 @@ class SiteRouteLoader extends Loader
|
|||
|
||||
$defaults = [
|
||||
'_controller' => $node->getController() ?? PageController::class.'::show',
|
||||
'_locale' => $navigation->getLocale(),
|
||||
'_node' => $node->getId(),
|
||||
'_menu' => $menu->getId(),
|
||||
'_page' => $node->getPage() ? $node->getPage()->getId() : null,
|
||||
|
@ -69,7 +80,15 @@ class SiteRouteLoader extends Loader
|
|||
}
|
||||
}
|
||||
|
||||
$route = new Route($node->getUrl(), $defaults, $requirements);
|
||||
$requirements['_locale'] = $navigation->getLocale();
|
||||
|
||||
$url = $node->getUrl();
|
||||
|
||||
if (!$uniqueness[$navigation->getDomain()]) {
|
||||
$url = sprintf('/%s%s', $navigation->getLocale(), $url);
|
||||
}
|
||||
|
||||
$route = new Route($url, $defaults, $requirements);
|
||||
$route->setHost($navigation->getDomain());
|
||||
|
||||
$routes->add($node->getRouteName(), $route);
|
||||
|
|
Loading…
Reference in a new issue