Пример #1
0
 public function onMainTopMenuTools(HookRenderBlockEvent $event)
 {
     $isGranted = $this->securityContext->isGranted(["ADMIN"], [], [BoSearch::getModuleCode()], [AccessManager::VIEW]);
     if ($isGranted) {
         $event->add(['title' => $this->trans('Search product', [], BoSearch::DOMAIN_NAME), 'url' => $this->router->generate('bosearch.product.view')]);
     }
 }
Пример #2
0
 public function defaultErrorFallback(GetResponseForExceptionEvent $event)
 {
     $this->parser->assign("status_code", 500);
     $this->parser->assign("exception_message", $event->getException()->getMessage());
     $this->parser->setTemplateDefinition($this->securityContext->hasAdminUser() ? $this->parser->getTemplateHelper()->getActiveAdminTemplate() : $this->parser->getTemplateHelper()->getActiveFrontTemplate());
     $response = new Response($this->parser->render(ConfigQuery::getErrorMessagePageName()), 500);
     $event->setResponse($response);
 }
Пример #3
0
 public function onMainBeforeContent(HookRenderEvent $event)
 {
     if ($this->securityContext->isGranted(["ADMIN"], [AdminResources::PRODUCT], [], [AccessManager::VIEW])) {
         $products = ProductQuery::create()->filterByVirtual(1)->filterByVisible(1)->count();
         if ($products > 0) {
             $deliveryModule = ModuleQuery::create()->retrieveVirtualProductDelivery();
             if (false === $deliveryModule) {
                 $event->add($this->render('virtual-delivery-warning.html'));
             }
         }
     }
 }
Пример #4
0
 public function loadCustomer()
 {
     $customer = CustomerQuery::create()->findOne();
     if (null === $customer) {
         return null;
     }
     $this->securityContext->setCustomerUser($customer);
     return $customer;
 }
Пример #5
0
 /**
  * Process security check function
  *
  * @param  array                                                   $params
  * @param  \Smarty                                                 $smarty
  * @return string                                                  no text is returned.
  * @throws \Thelia\Core\Security\Exception\AuthenticationException
  * @throws AuthenticationException
  * @throws AuthorizationException
  */
 public function checkAuthFunction($params, &$smarty)
 {
     $roles = $this->explode($this->getParam($params, 'role'));
     $resources = $this->explode($this->getParam($params, 'resource'));
     $modules = $this->explode($this->getParam($params, 'module'));
     $accesses = $this->explode($this->getParam($params, 'access'));
     if (!$this->securityContext->isGranted($roles, $resources, $modules, $accesses)) {
         if (null === $this->securityContext->checkRole($roles)) {
             // The current user is not logged-in.
             $ex = new AuthenticationException(sprintf("User not granted for roles '%s', to access resources '%s' with %s.", implode(',', $roles), implode(',', $resources), implode(',', $accesses)));
             $loginTpl = $this->getParam($params, 'login_tpl');
             if (null != $loginTpl) {
                 $ex->setLoginTemplate($loginTpl);
             }
         } else {
             // We have a logged-in user, who do not have the proper permission. Issue an AuthorizationException.
             $ex = new AuthorizationException(sprintf("User not granted for roles '%s', to access resources '%s' with %s.", implode(',', $roles), implode(',', $resources), implode(',', $accesses)));
         }
         throw $ex;
     }
     return '';
 }
Пример #6
0
 /**
  * @param OrderEvent $event
  *
  * @throws \Thelia\Exception\TheliaProcessException
  */
 public function create(OrderEvent $event)
 {
     $session = $this->getSession();
     $placedOrder = $this->createOrder($event->getDispatcher(), $event->getOrder(), $session->getCurrency(), $session->getLang(), $session->getCart(), $this->securityContext->getCustomerUser());
     $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
     /* but memorize placed order */
     $event->setOrder(new \Thelia\Model\Order());
     $event->setPlacedOrder($placedOrder);
     /* empty cart */
     $dispatcher = $event->getDispatcher();
     /* call pay method */
     $payEvent = new OrderPaymentEvent($placedOrder);
     $dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);
     if ($payEvent->hasResponse()) {
         $event->setResponse($payEvent->getResponse());
     }
 }
Пример #7
0
 /**
  * @param OrderEvent $event
  *
  * @throws \Thelia\Exception\TheliaProcessException
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function create(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $session = $this->getSession();
     $order = $event->getOrder();
     $paymentModule = ModuleQuery::create()->findPk($order->getPaymentModuleId());
     /** @var \Thelia\Module\PaymentModuleInterface $paymentModuleInstance */
     $paymentModuleInstance = $paymentModule->createInstance();
     $placedOrder = $this->createOrder($dispatcher, $event->getOrder(), $session->getCurrency(), $session->getLang(), $session->getSessionCart($dispatcher), $this->securityContext->getCustomerUser(), $paymentModuleInstance->manageStockOnCreation());
     $dispatcher->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
     /* but memorize placed order */
     $event->setOrder(new OrderModel());
     $event->setPlacedOrder($placedOrder);
     /* call pay method */
     $payEvent = new OrderPaymentEvent($placedOrder);
     $dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);
     if ($payEvent->hasResponse()) {
         $event->setResponse($payEvent->getResponse());
     }
 }
 /**
  * Provides access to the current logged customer attributes thought the accessor
  *
  * @param  array $params
  * @param  \Smarty $smarty
  * @return string the value of the requested attribute
  */
 public function customerDataAccess($params, &$smarty)
 {
     return $this->dataAccess("Customer User", $params, $this->securityContext->getCustomerUser());
 }
Пример #9
0
 /**
  * Perform user logout. The user is redirected to the provided view, if any.
  *
  * @param ActionEvent $event
  */
 public function logout(ActionEvent $event)
 {
     $this->securityContext->clearCustomerUser();
 }