Browse Source

Correctif switch merchant crsf token

packProduct
Fabien Normand 2 years ago
parent
commit
cdddcac5c4
7 changed files with 45 additions and 32 deletions
  1. +8
    -10
      Controller/Merchant/FavoriteMerchantAdminController.php
  2. +8
    -9
      Controller/Merchant/FavoriteMerchantController.php
  3. +18
    -6
      Controller/Merchant/SwitchMerchantController.php
  4. +2
    -0
      Definition/ActionDefinition.php
  5. +6
    -1
      Resources/translations/admin.fr.yaml
  6. +1
    -1
      Resources/views/adminlte/layout.html.twig
  7. +2
    -5
      Twig/FormTwigExtension.php

+ 8
- 10
Controller/Merchant/FavoriteMerchantAdminController.php View File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -27,22 +28,19 @@ class FavoriteMerchantAdminController extends AbstractController
if ($merchant) {

$user = $security->getUser();
if($user) {
if ($user) {
$user->setFavoriteMerchant($merchant);
$entityManager->update($user);
$entityManager->flush();
}

// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
}

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
}

return $this->redirect($request->headers->get('referer'));
}
}

+ 8
- 9
Controller/Merchant/FavoriteMerchantController.php View File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -33,16 +34,14 @@ class FavoriteMerchantController extends AbstractController
$entityManager->flush();
}

// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
}

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
}

return $this->redirect($request->headers->get('referer'));
}

}

+ 18
- 6
Controller/Merchant/SwitchMerchantController.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;

use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -16,7 +17,11 @@ class SwitchMerchantController extends AbstractController
*/
public function switchMerchant(Request $request)
{
$form = $this->createForm(SwitchMerchantFormType::class);
$form = $this->createForm(
SwitchMerchantFormType::class,
null,
array('csrf_protection' => false)
);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
@@ -25,19 +30,26 @@ class SwitchMerchantController extends AbstractController

if ($merchant) {
$url = $this->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
$merchant,
MerchantSettingDefinition::SETTING_URL
);

if ($context == 'admin') {
$url .= 'admin';
}

if ($url) {
return $this->redirect($url);
}

}
}

if ($url) {
return $this->redirect($url);
} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_MERCHANT, 'Merchant');
return $this->redirect($request->headers->get('referer'));
}


}

}

+ 2
- 0
Definition/ActionDefinition.php View File

@@ -8,6 +8,8 @@ class ActionDefinition extends SovActionDefinition{
public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant';
public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection';
public const EDIT_ADDRESS_USER = 'editAddressUser';
public const SWITCH_MERCHANT = 'switchMerchant';
public const SWITCH_FAVORITE_MERCHANT = 'switchFavoriteMerchant';


}

+ 6
- 1
Resources/translations/admin.fr.yaml View File

@@ -112,7 +112,12 @@ entity:
Merchant:
label: Marchand
label_plurial: Marchands

flashes:
error:
switchMerchant: Une erreur est survenue lors du changement de marchand, veuillez réessayer.
switchFavoriteMerchant: Une erreur est survenue lors de la sauvegarde de votre marchand favoris.
success:
switchFavoriteMerchant: "%merchant% est maintenant votre marchand favoris."
Section:
label: Section
label_plurial: Sections

+ 1
- 1
Resources/views/adminlte/layout.html.twig View File

@@ -23,7 +23,7 @@
<ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i>
{% set form_switch_merchant = carac_form_switch_merchant('admin') %}
{% set form_switch_merchant = carac_form_switch_merchant('admin', 'carac_merchant_switch', false) %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}

+ 2
- 5
Twig/FormTwigExtension.php View File

@@ -2,12 +2,8 @@

namespace Lc\CaracoleBundle\Twig;

use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Extension\AbstractExtension;
@@ -34,7 +30,7 @@ class FormTwigExtension extends AbstractExtension
);
}

public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch')
public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch', $csrfProtection = true)
{
$form = $this->formFactory->create(
SwitchMerchantFormType::class,
@@ -42,6 +38,7 @@ class FormTwigExtension extends AbstractExtension
[
'action' => $this->urlGenerator->generate($actionRoute),
'attr' => ['class' => 'switch-merchant'],
'csrf_protection' => $csrfProtection,
'context' => $context
]
);

Loading…
Cancel
Save