public function switchLocaleAction(Request $request)
 {
     $this->guard->userIsLoggedIn();
     $this->logger->notice('User requested to switch locale');
     $returnUrl = $request->query->get('return-url');
     // Return URLs generated by us always include a path (ie. at least a forward slash)
     // @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L878
     $domain = $request->getSchemeAndHttpHost() . '/';
     if (strpos($returnUrl, $domain) !== 0) {
         $this->logger->error(sprintf('Illegal return-url ("%s") for redirection after changing locale, aborting request', $returnUrl));
         throw new BadRequestHttpException('Invalid return-url given');
     }
     $command = new ChangeLocaleCommand();
     $form = $this->formFactory->create('profile_switch_locale', $command, [])->handleRequest($request);
     $this->logger->notice(sprintf('Switching locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
     if ($form->isValid()) {
         $this->userService->changeLocale($command);
         $this->flashBag->add('success', 'profile.locale.locale_change_success');
         $this->logger->notice(sprintf('Successfully switched locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
     } else {
         $this->flashBag->add('error', 'profile.locale.locale_change_fail');
         $this->logger->error('Locale not switched: the switch locale form contained invalid data');
     }
     return new RedirectResponse($returnUrl);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function checkPreAuth(UserInterface $user)
 {
     parent::checkPreAuth($user);
     if ($user instanceof User && null !== $this->securityContextLink->getService()->getToken() && null !== $user->getPasswordChangedAt() && null !== $user->getLastLogin() && $user->getPasswordChangedAt() > $user->getLastLogin()) {
         $this->flashBag->add('error', $this->translator->trans('oro.user.security.password_changed.message'));
         $exception = new PasswordChangedException('Invalid password.');
         $exception->setUser($user);
         throw $exception;
     }
 }
Пример #3
0
 /**
  * Adds a flash message to the current session for type.
  *
  * @param string $type    The type
  * @param string $message The message
  *
  * @throws \LogicException
  */
 protected function addFlash($type, $message)
 {
     if ($this->flashBag === null) {
         throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
     }
     $this->flashBag->add($type, $message);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess(User $user)
 {
     $this->manager->updateUser($user);
     if ($this->form->has('inviteUser') && $this->form->has('plainPassword') && $this->form->get('inviteUser')->getViewData() && $this->form->get('plainPassword')->getViewData()) {
         try {
             $this->sendInviteMail($user, $this->form->get('plainPassword')->getViewData()['first']);
         } catch (\Exception $ex) {
             $this->logger->error('Invitation email sending failed.', ['exception' => $ex]);
             $this->flashBag->add('warning', $this->translator->trans('oro.user.controller.invite.fail.message'));
         }
     }
     // Reloads the user to reset its username. This is needed when the
     // username or password have been changed to avoid issues with the
     // security layer.
     // Additional checking for userConfigManager !== null is added because of API
     // to avoid "Call to a member function on a non-object".
     $this->manager->reloadUser($user);
     if ($this->form->has('signature') && $this->userConfigManager !== null) {
         $signature = $this->form->get('signature')->getData();
         if ($signature) {
             $this->userConfigManager->set('oro_email.signature', $signature);
         } else {
             $this->userConfigManager->reset('oro_email.signature');
         }
         $this->userConfigManager->flush();
     }
 }
 function it_adds_error_message_to_flashbag_when_coupon_is_not_eligible(GenericEvent $event, FlashBagInterface $flashBag, $session, $translator)
 {
     $event->getName()->willReturn(SyliusPromotionEvents::COUPON_NOT_ELIGIBLE);
     $translator->trans(Argument::any(), Argument::any(), 'flashes')->shouldBeCalled();
     $flashBag->add('error', Argument::any())->shouldBeCalled();
     $session->getBag('flashes')->shouldBeCalled()->willReturn($flashBag);
     $this->handleCouponPromotion($event);
 }
 function it_deletes_user_if_there_is_no_token(TokenStorageInterface $tokenStorage, FlashBagInterface $flashBag, GenericEvent $event, UserInterface $userToBeDeleted)
 {
     $event->getSubject()->willReturn($userToBeDeleted);
     $userToBeDeleted->getId()->willReturn(11);
     $tokenStorage->getToken()->willReturn(null);
     $event->stopPropagation()->shouldNotBeCalled();
     $flashBag->add('error', Argument::any())->shouldNotBeCalled();
     $this->deleteUser($event);
 }
 function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, FlashBagInterface $flashBag, StockableInterface $stockable)
 {
     $stockable->getOnHand()->willReturn('30');
     $stockable->getInventoryName()->willReturn('Inventory Name');
     $event->getException()->willReturn(new InsufficientStockException($stockable->getWrappedObject(), 42));
     $event->setResponse(Argument::type(RedirectResponse::class))->shouldBeCalled();
     $translator->trans('sylius.checkout.out_of_stock', ['%quantity%' => '30', '%name%' => 'Inventory Name'], 'flashes')->willReturn('message translated');
     $flashBag->add('notice', 'message translated')->shouldBeCalled();
     $session->getBag('flashes')->willReturn($flashBag);
     $router->generate('redirect_to_url')->willReturn('url');
     $this->onKernelException($event);
 }
 /**
  * @param GetResponseForExceptionEvent $event
  *
  * @return void
  * @author Michaël VEROUX
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof AccessDeniedException) {
         $exception = null;
         try {
             parent::onKernelException($event);
         } catch (\Exception $e) {
             $exception = $e;
         }
         if (!$exception instanceof HttpExceptionInterface && !$event->getException() instanceof HttpExceptionInterface && 'prod' === $this->mode) {
             $this->loggerDb->error($event->getException()->getMessage(), array('exception' => $event->getException()));
             if ($this->flashBag) {
                 if (null === $this->lastError->getId()) {
                     $this->flashBag->add('error', 'Une erreur est survenue');
                 } else {
                     $this->flashBag->add('error', sprintf('Une erreur est survenue #%s', $this->lastError->getId()));
                 }
             }
         }
     }
 }
 function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, InsufficientStockException $exception, FlashBagInterface $flashBag, StockableInterface $stockable)
 {
     $stockable->getOnHand()->shouldBeCalled()->willReturn('30');
     $stockable->getInventoryName()->shouldBeCalled()->willReturn('Inventory Name');
     $exception->getStockable()->shouldBeCalledTimes(2)->willReturn($stockable);
     $event->getException()->shouldBeCalled()->willReturn($exception);
     $event->setResponse(Argument::type('Symfony\\Component\\HttpFoundation\\RedirectResponse'))->shouldBeCalled();
     $translator->trans('sylius.checkout.out_of_stock', array('%quantity%' => '30', '%name%' => 'Inventory Name'), 'flashes')->shouldBeCalled()->willReturn('message translated');
     $flashBag->add('notice', 'message translated')->shouldBeCalled();
     $session->getBag('flashes')->shouldBeCalled()->willReturn($flashBag);
     $router->generate('redirect_to_url')->shouldBeCalled()->willReturn('url');
     $this->onKernelException($event)->shouldReturn(null);
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess(User $user)
 {
     $this->manager->updateUser($user);
     $this->tagManager->saveTagging($user);
     if ($this->form->has('inviteUser') && $this->form->has('plainPassword') && $this->form->get('inviteUser')->getViewData() && $this->form->get('plainPassword')->getViewData()) {
         try {
             $this->sendInviteMail($user, $this->form->get('plainPassword')->getViewData()['first']);
         } catch (\Exception $ex) {
             $this->logger->error('Invitation email sending failed.', array('exception' => $ex));
             $this->flashBag->add('warning', $this->translator->trans('oro.user.controller.invite.fail.message'));
         }
     }
     // Reloads the user to reset its username. This is needed when the
     // username or password have been changed to avoid issues with the
     // security layer.
     $this->manager->reloadUser($user);
 }
Пример #11
0
 function it_should_set_error_flash_message_if_payment_status_unknown(TranslatorInterface $translator, FlashBagInterface $flashBag, PurchaseCompleteEvent $event, PaymentInterface $payment)
 {
     $payment->getState()->willReturn(PaymentInterface::STATE_UNKNOWN);
     $translator->trans('sylius.checkout.unknown', [], 'flashes')->shouldBeCalled()->willReturn('translated.sylius.checkout.unknown');
     $flashBag->add('error', 'translated.sylius.checkout.unknown')->shouldBeCalled();
     $this->addFlash($event);
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public function attachFlashBag(FlashBagInterface $flashBag)
 {
     if ($this->flashBag) {
         return;
     }
     $this->flashBag = $flashBag;
     // We iterate as some flashes might validly be set in Twig
     // and we shouldn't wipe them.
     foreach ($this->flashes as $type => $messages) {
         foreach ($messages as $message) {
             $flashBag->add($type, $message);
         }
         unset($this->flashes[$type]);
     }
 }
 public function it_accepts_redirection_options(ManagerInterface $manager, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, Entity $object, FormFactoryInterface $formFactory, FormInterface $form, FlashBagInterface $flashBag)
 {
     $request->isMethod('post')->willReturn(true);
     $form->submit($request)->shouldBeCalled();
     $form->isValid()->willReturn(true);
     $manager->create('entity_class', [], [])->willReturn($object);
     $manager->save($object, [])->shouldBeCalled();
     $object->getId()->willReturn(null);
     $formFactory->create('form_type', $object, ['f_param1' => 'value1', 'data_class' => 'entity_class'])->shouldBeCalled()->willReturn($form);
     $configuration->getActionOptions('create')->willReturn(['form_type' => 'form_type', 'form_options' => ['f_param1' => 'value1'], 'redirect_route' => 'redirect_route', 'redirect_route_parameters' => ['c_r_param1' => 'value1'], 'success_message' => 'success_message']);
     $configuration->hasAction('delete')->willReturn(false);
     $flashBag->add('success', '<success_message>')->shouldBeCalled();
     $this->initializeEventManager($eventManager);
     $this->setConfiguration($configuration);
     $response = $this->execute($request);
     $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse');
     $response->getTargetUrl()->shouldReturn('redirect_route?&c_r_param1=value1');
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 public function success($message)
 {
     $this->flashBag->add(FlashNotifierInterface::TYPE_SUCCESS, $message);
 }
Пример #15
0
 /**
  * @param string $key
  * @param string $value
  *
  * @return void
  */
 protected function addToFlashBag($key, $value)
 {
     $this->flashBag->add($key, $value);
 }
Пример #16
0
 /**
  * Adds a flash message.
  *
  * @param array|string $flash
  * @param string|null  $type
  * @param int|null     $delay
  */
 public function add($flash, $type = null, $delay = null)
 {
     $flash = $this->prepare($flash, $type, $delay);
     $this->flashBag->add($this->storageKey, $flash);
 }