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);
 }
 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);
 }
Пример #4
0
 /**
  * @param UserInterface $user
  * @param int           $getTokenCalls
  * @param string        $token
  * @param boolean       $exceptionThrown
  *
  * @dataProvider checkPreAuthProvider
  */
 public function testCheckPreAuth(UserInterface $user, $getTokenCalls, $token, $exceptionThrown)
 {
     $this->service->expects($this->exactly($getTokenCalls))->method('getToken')->willReturn($token);
     if ($exceptionThrown) {
         $this->flashBag->expects($this->once())->method('add')->with('error', 'oro.user.security.password_changed.message');
         $this->setExpectedException('Oro\\Bundle\\UserBundle\\Exception\\PasswordChangedException', 'Invalid password.');
     }
     $this->userChecker->checkPreAuth($user);
 }
Пример #5
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;
     }
 }
Пример #6
0
 private function add($type, $message, $domain)
 {
     if ($this->flashBag->has($this->prefix)) {
         $messages = $this->flashBag->get($this->prefix);
     } else {
         $messages = [];
     }
     $messages[$type][] = ['text' => $message, 'domain' => $domain];
     $this->flashBag->set($this->prefix, $messages);
 }
 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);
 }
 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);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->bag = new FlashBag();
     $this->array = array('notice' => array('A previous flash message'));
     $this->bag->initialize($this->array);
 }
Пример #10
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();
     }
 }
Пример #11
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);
 }
Пример #12
0
 public function testPeekAll()
 {
     $this->bag->set('notice', 'Foo');
     $this->bag->set('error', 'Bar');
     $this->assertEquals(array('notice' => array('Foo'), 'error' => array('Bar')), $this->bag->peekAll());
     $this->assertTrue($this->bag->has('notice'));
     $this->assertTrue($this->bag->has('error'));
     $this->assertEquals(array('notice' => array('Foo'), 'error' => array('Bar')), $this->bag->peekAll());
 }
Пример #13
0
 /**
  * @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()));
                 }
             }
         }
     }
 }
Пример #14
0
 /**
  * @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator
  * @group legacy
  */
 public function testLegacyGetIterator()
 {
     $flashes = array('hello' => 'world', 'beep' => 'boop', 'notice' => 'nope');
     foreach ($flashes as $key => $val) {
         $this->bag->set($key, $val);
     }
     $i = 0;
     foreach ($this->bag as $key => $val) {
         $this->assertEquals(array($flashes[$key]), $val);
         ++$i;
     }
     $this->assertEquals(count($flashes), $i);
     $this->assertCount(0, $this->bag->all());
 }
 /**
  * @covers Symfony\Component\HttpFoundation\Session\Flash\FlashBag::getIterator
  */
 public function testLegacyGetIterator()
 {
     $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
     $flashes = array('hello' => 'world', 'beep' => 'boop', 'notice' => 'nope');
     foreach ($flashes as $key => $val) {
         $this->bag->set($key, $val);
     }
     $i = 0;
     foreach ($this->bag as $key => $val) {
         $this->assertEquals(array($flashes[$key]), $val);
         $i++;
     }
     $this->assertEquals(count($flashes), $i);
     $this->assertCount(0, $this->bag->all());
 }
Пример #16
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);
 }
 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');
 }
Пример #18
0
 /**
  * Constructeur.
  * 
  * @param \Symfony\Component\HttpFoundation\Session\SessionInterface        $session  Session
  * @param \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $flashBag FlashBag
  */
 public function __construct(SessionInterface $session, FlashBagInterface $flashBag = null)
 {
     $this->sessionFlashBag = $session->getBag($flashBag->getName());
 }
Пример #19
0
 public function getNotices()
 {
     return $this->bag->all();
 }
Пример #20
0
 /**
  * Tests the success() method.
  *
  * @covers Braincrafted\Bundle\BootstrapBundle\Session\FlashMessage::__construct()
  * @covers Braincrafted\Bundle\BootstrapBundle\Session\FlashMessage::success()
  */
 public function testSuccess()
 {
     $this->flashBag->shouldReceive('add')->with('success', 'Foobar Success')->once();
     $this->flash->success('Foobar Success');
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function success($message)
 {
     $this->flashBag->add(FlashNotifierInterface::TYPE_SUCCESS, $message);
 }
Пример #22
0
 /**
  * @param string $key
  * @param string $value
  *
  * @return void
  */
 protected function addToFlashBag($key, $value)
 {
     $this->flashBag->add($key, $value);
 }
Пример #23
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);
 }
Пример #24
0
 /**
  * Has flash messages?
  *
  * @return bool
  */
 public function has()
 {
     return $this->flashBag->has($this->storageKey);
 }
Пример #25
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]);
     }
 }
Пример #26
0
 /**
  * Check for flash alerts.
  *
  * @return bool
  */
 public function hasFlashAlerts()
 {
     return 0 < count($this->flashBag->peek(self::FLASH_BAG_KEY));
 }
Пример #27
0
 /**
  * Get flash alerts.
  *
  * @return array
  */
 public function getFlashAlerts()
 {
     return $this->flashBag->get('silvestra_notification_alerts');
 }