diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 05a104d7989409b72f52fd86b022462b9be0abfe..d04ac4093334636d10f9071c4220e70b5d726570 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -35,3 +35,4 @@ security: access_control: - { path: ^/(?!register|login|generate-captcha|verify/email|reset-password), roles: ROLE_USER } + - { path: ^/*/edition, roles: ROLE_EDITOR } \ No newline at end of file diff --git a/src/Controller/CapsuleController.php b/src/Controller/CapsuleController.php index 94cd95f0d6d1efc6698e2a402882d10349109b4f..0226e8cb550dfeb59ae0489fcc1d290aba868621 100644 --- a/src/Controller/CapsuleController.php +++ b/src/Controller/CapsuleController.php @@ -7,6 +7,7 @@ use App\Form\CreateCapsuleFormType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Annotation\Route; class CapsuleController extends AbstractController @@ -25,7 +26,7 @@ class CapsuleController extends AbstractController /** * @Route("/create", name="create_capsule") */ - public function new(Request $request): Response + public function new(Request $request, UserPasswordHasherInterface $password_hasher): Response { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED'); @@ -34,16 +35,20 @@ class CapsuleController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $capsulePass = $request->request->get('p'); +// $capsulePass = $request->request->get('p'); $new_date_time = new \DateTime(); - $video_url = $form->get('video_url')->getData(); + $capsule_name = $form->get('name')->getData(); +// $sanitized_capsule_name = $this->sanitize($capsule_name); - $capsule->setName($this->sanitize($form->get('name')->getData())); - $capsule->setVideoUrl($video_url); + $preview_link = password_hash($capsule_name, PASSWORD_BCRYPT); + $edition_link = $preview_link . '/edition'; + + $capsule->setName($capsule_name); $capsule->setCreationAuthor($this->getUser()); $capsule->setCreationDate($new_date_time); $capsule->setUpdatedDate($new_date_time); - $capsule->setEditionLink($video_url . '/?p=' . $capsulePass); + $capsule->setPreviewLink($preview_link); + $capsule->setEditionLink($edition_link); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($capsule); diff --git a/src/Entity/Capsule.php b/src/Entity/Capsule.php index 4ea63146837c375e26876023d41066cd15093706..08e8a4a69a399d2a0156fe630f05125772e53616 100644 --- a/src/Entity/Capsule.php +++ b/src/Entity/Capsule.php @@ -65,7 +65,7 @@ class Capsule * * @ORM\Column(name="link", type="string", length=255, nullable=false) */ - private string $video_url; + private string $preview_link; /** * @@ -124,12 +124,12 @@ class Capsule return $this; } - public function getVideoUrl() { - return $this->video_url; + public function getPreviewLink() { + return $this->preview_link; } - public function setVideoUrl(string $video_url) { - $this->video_url = $video_url; + public function setPreviewLink(string $preview_link) { + $this->preview_link = $preview_link; return $this; } diff --git a/src/Form/CreateCapsuleFormType.php b/src/Form/CreateCapsuleFormType.php index 9a17d98e8b9b67adf96b7266ad7a2e42da43fadf..48670617d9fd2b0ba906566eb73f38ab2077d335 100644 --- a/src/Form/CreateCapsuleFormType.php +++ b/src/Form/CreateCapsuleFormType.php @@ -27,6 +27,7 @@ class CreateCapsuleFormType extends AbstractType 'video_url', UrlType::class, [ + 'mapped' => false, 'constraints' => [new NotBlank(['message' => 'capsule.video_url.not_blank'])], 'label' => 'capsule.video_url' ]) diff --git a/templates/capsule/create.html.twig b/templates/capsule/create.html.twig index c5cec2d158fe6430073893051450611f1321c383..2c1cf8f7e7459d4aa090493d63acbfd08093236d 100644 --- a/templates/capsule/create.html.twig +++ b/templates/capsule/create.html.twig @@ -14,9 +14,9 @@ </div> {{ form_start(capsuleCreationForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }} - {{ form_row(capsuleCreationForm.name, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }} - {{ form_row(capsuleCreationForm.video_url, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }} - {{ form_row(capsuleCreationForm.save, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-5 col-2'}}) }} + {{ form_row(capsuleCreationForm.name, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }} + {{ form_row(capsuleCreationForm.video_url, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }} + {{ form_row(capsuleCreationForm.save, {'row_attr': {'class' : 'm-auto mb-5 col-2'}}) }} {{ form_end(capsuleCreationForm) }} </div> diff --git a/templates/capsule/index.html.twig b/templates/capsule/index.html.twig index 6a7e471c5008f42388e8c3fed24508fa32653b2b..d668298e724b491d469006298910087c2878e343 100644 --- a/templates/capsule/index.html.twig +++ b/templates/capsule/index.html.twig @@ -1,6 +1,10 @@ {% extends 'layout.html.twig' %} -{% block title %}Hello CapsuleController!{% endblock %} +{% block title %} + {{ 'capsule.title'|trans }} + - + {{ parent() }} +{% endblock %} {% block body %} diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index b5746af46cbdb536e0837daaa6aacb739bbef5fa..6469565c09d3c6ad5728a78ca14dd684f3cd769b 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -41,6 +41,7 @@ email_reset_password: greeting: Cheers! capsule: + title: My capsules create_capsule: Create a capsule name: Name of the capsule video_url: Youtube or Vimeo video URL \ No newline at end of file