@Route("/setToken/", name="KunstmaanDashboardBundle_setToken")

@param Request $request

@throws AccessDeniedException

@return array
334275
public function setTokenAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

        $code = urldecode($request->query->get('code'));

        if (isset($code)) {
            $clientHelper = $this->container->get('kunstmaan_dashboard.helper.google.client');
            $configHelper = $this->container->get('kunstmaan_dashboard.helper.google.analytics.config');

            $clientHelper->getClient()->authenticate($code);
            $configHelper->saveToken($clientHelper->getClient()->getAccessToken());

            return $this->redirect($this->generateUrl('KunstmaanDashboardBundle_Config'));
        }

        return $this->redirect($this->generateUrl('KunstmaanDashboardBundle_widget_googleanalytics'));
    }
91933
public function composeContainerShowAction(Request $request = null)
    {
        if (false === $this->get('sonata.page.admin.block')->isGranted('LIST')) {
            throw new AccessDeniedException();
        }

        $id = $request->get($this->admin->getIdParameter());
        $block = $this->get('sonata.page.admin.block')->getObject($id);
        if (!$block) {
            throw new NotFoundHttpException(sprintf('unable to find the block with id : %s', $id));
        }

        $blockServices = $this->get('sonata.block.manager')->getServicesByContext('sonata_page_bundle', false);

        // filter service using the template configuration
        if ($page = $block->getPage()) {
            $template = $this->get('sonata.page.template_manager')->get($page->getTemplateCode());

            $container = $template->getContainer($block->getSetting('code'));

            if (isset($container['blocks']) && \count($container['blocks']) > 0) {
                foreach ($blockServices as $code => $service) {
                    if (\in_array($code, $container['blocks'], true)) {
                        continue;
                    }

                    unset($blockServices[$code]);
                }
            }
        }

        return $this->render($this->admin->getTemplate('compose_container_show'), [
            'blockServices' => $blockServices,
            'container' => $block,
            'page' => $block->getPage(),
        ]);
    }
356443
protected function getToken(Request $request)
    {
        try {
            $this->validateAuthorizationHeader($request);

            $token = $this->parseAuthorizationHeader($request);
        } catch (Exception $exception) {
            if (! $token = $request->query('token', false)) {
                throw $exception;
            }
        }

        return $token;
    }
1335098
public function getCredentials(Request $request)
    {
        // Get token and key
        $headerToken  = $request->headers->get('X-APP-TOKEN');

        if (!$headerToken) {
            // no token, nonce or app? Return null and no other methods will be called
            return;
        }

        // What you return here will be passed to getUser() as $credentials
        $token = new Token;
        $token->fromHeader($headerToken);

        return array(
            'token'     => $token,
            'header'    => $headerToken,
        );
    }
982784
public function getPayload($request = null)
    {
        if (!$request) {
            return $this->_payload;
        }

        $payload = null;

        $token = $this->getToken($request);
        if ($token) {
            $payload = $this->_decode($token);
        }

        return $this->_payload = $payload;
    }
152430
private function readToken(Request $request)
    {
        if (!$request->hasRedirectHeader('HTTP_AUTHORIZATION')) {
            return null;
        }

        return $request->readRedirectHeader('HTTP_AUTHORIZATION')
                ->withFilter(TokenFilter::instance());
    }
1202919
protected function getTokensAction(Request $request)
    {
        // Get an array representation of the current payload (of last save) for context.
        // No longer needs filePayload.
        $payload     = html_entity_decode(InputHelper::clean($request->request->get('apiPayload')));
        $defaultFile = __DIR__.ContactClient::API_PAYLOAD_DEFAULT_FILE;
        if (
            $payload
            && file_exists($defaultFile)
            && $payload == file_get_contents($defaultFile)
        ) {
            $cacheKey = 'tokenCacheDefault';
            $cacheTtl = 3600;
        } else {
            $cacheKey = 'tokenCache'.md5($payload);
            $cacheTtl = 300;
        }
        $payload   = json_decode($payload, true);
        $payload   = is_array($payload) ? $payload : [];
        $cache     = new CacheStorageHelper(
            CacheStorageHelper::ADAPTOR_FILESYSTEM,
            'ContactClient',
            null,
            $this->coreParametersHelper->getParameter(
                'cached_data_dir',
                $this->get('mautic.helper.paths')->getSystemPath('cache', true)
            ),
            300
        );
        $dataArray = $cache->get($cacheKey, $cacheTtl);
        if (!$dataArray) {
            $dataArray = [
                'tokens'  => [],
                'types'   => [],
                'formats' => [],
                'success' => 0,
            ];

            /** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
            $fieldModel = $this->get('mautic.lead.model.field');

            // Exclude company fields as they are not currently used by the token helper.
            $fields      = $fieldModel->getEntities(
                [
                    'filter'         => [
                        'force' => [
                            [
                                'column' => 'f.isPublished',
                                'expr'   => 'eq',
                                'value'  => true,
                            ],
                            [
                                'column' => 'f.object',
                                'expr'   => 'notLike',
                                'value'  => 'company',
                            ],
                        ],
                    ],
                    'hydration_mode' => 'HYDRATE_ARRAY',
                ]
            );
            $contact     = new Contact();
            $fieldGroups = [];
            foreach ($fields as $field) {
                $fieldGroups[$field['group']][$field['alias']] = [
                    'value' => $field['label'],
                    'type'  => $field['type'],
                    'label' => $field['label'],
                ];
            }
            $contact->setFields($fieldGroups);

            /** @var TokenHelper $tokenHelper */
            $tokenHelper = $this->get('mautic.contactclient.helper.token');
            $tokenHelper->newSession(null, $contact, $payload);

            $tokens = $tokenHelper->getContextLabeled();
            if ($tokens) {
                $dataArray['success'] = true;
                $dataArray['tokens']  = $tokens;
                $dataArray['types']   = $tokenHelper->getContextTypes();
                $dataArray['formats'] = $tokenHelper->getFormats();
            }
            $cache->set($cacheKey, $dataArray, $cacheTtl);
        }

        return $this->sendJsonResponse($dataArray);
    }
500635
private function authenticateRequest(RequestInterface $request, AccessToken $token)
    {
        foreach ($this->provider->getHeaders($token->getToken()) as $name => $value) {
            $request = $request->withHeader($name, $value);
        }

        return $request;
    }
1194777
private function createToken(Request $request)
    {
        $tokenString = $request->headers->get($this->header);

        if ($this->header == self::HEADER_AUTH && 0 === strpos((string)$tokenString, 'Bearer ')) {
            $tokenString = substr($tokenString, 7);
        }

        if (!$tokenString) {
            return null;
        }

        return new JwtAuthenticationToken([], $tokenString);
    }
361125
public function changePasswordAction(Request $request)
    {
        $user = $this->container->get('security.context')->getToken()->getUser();
        if (!is_object($user) || !$user instanceof UserInterface) {
            throw new AccessDeniedException('This user does not have access to this section.');
        }

        /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
        $dispatcher = $this->container->get('event_dispatcher');

        $event = new GetResponseUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->container->get('fos_user.change_password.form.factory');

        $form = $formFactory->createForm();
        $form->setData($user);

        $form->bind($request->query->get("params"));
        if ($form->isValid()) {
            /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
            $userManager = $this->container->get('fos_user.user_manager');

            $event = new FormEvent($form, $request);
            $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event);

            $userManager->updateUser($user);

            if (null === $response = $event->getResponse()) {
                $response = new JsonResponse(array(
                	"success" => true
                ));
            }

            $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

            return $response;
        }
        $errors = array();
        foreach ($form->getErrors(true) as $error) {
        	$errors[] = $error->getMessage();
        }
		return new JsonResponse(array(
               	"success" => false,
				"errors" => $errors
        ));
    }
342041
public function indexAction(Request $request)
    {
        $this->init($request);

        $nodeAdminListConfigurator = new NodeAdminListConfigurator(
            $this->em,
            $this->aclHelper,
            $this->locale,
            PermissionMap::PERMISSION_VIEW,
            $this->authorizationChecker
        );

        $locale = $this->locale;
        $acl = $this->authorizationChecker;
        $itemRoute = function (EntityInterface $item) use ($locale, $acl) {
            if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) {
                return array(
                    'path' => '_slug_preview',
                    'params' => ['_locale' => $locale, 'url' => $item->getUrl()],
                );
            }
        };
        $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye');
        $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration'));
        $nodeAdminListConfigurator->setShowAddHomepage($this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN'));

        /** @var AdminList $adminlist */
        $adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator);
        $adminlist->bindRequest($request);

        return array(
            'adminlist' => $adminlist,
        );
    }
591195
public function fetchToken(Request $request)
    {
        foreach ($this->config->getOperators() as $name) {
            $operator = $this->getOperator($name);

            if ($operator->hasToken($request)) {
                return $operator->fetchToken($request);
            }
        }

        return null;
    }
802450
protected function getRequestToken(Request $request)
    {
        /** @var TokenExtractorInterface $tokenExtractor */
        foreach ($this->tokenExtractors as $tokenExtractor) {
            if (($token = $tokenExtractor->extract($request))) {
                return $token;
            }
        }
    }
834389
public function clearAction(Request $request)
    {
        if (!$this->getParameter('kernel.debug')) {
            throw new AccessDeniedException('You should be in debug mode to access this feature');
        }
        $this->get('victoire_widget.widget_cache')->clear();

        return $this->redirect($request->headers->get('referer'));
    }
1319696
public function batchTranslateAction(Request $request)
    {
        if ($this->admin->isGranted('ROLE_SUPER_ADMIN') === false) {
            throw new AccessDeniedException();
        }

        $form = $this->createForm('Networking\InitCmsBundle\Form\Type\PageBatchCopyType', [],
            ['locales' => $this->getParameter('networking_init_cms.page.languages')]);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();

            /** @var PageHelper $pageHelper */
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

            $pages = $this->admin->getModelManager()->findBy($this->admin->getClass(), ['locale' => $data['fromLocale']]);
            /** @var PageInterface $page */
            foreach ($pages as $page) {
                $translatedLocales = $page->getTranslatedLocales();

                if (in_array($data['toLocale'], $translatedLocales)) {
                    continue;
                }
                $pageHelper->makeTranslationCopy($page, $data['toLocale']);
            }

            $this->get('session')->getFlashBag()->add('sonata_flash_success', 'flash_batch_copy_success');
        }

        return $this->renderWithExtraParams('@NetworkingInitCms/PageAdmin/batch_page_copy.html.twig',
            ['action' => 'batchCopy', 'form' => $form->createView()]
        );
    }
1045393
public function handle($request, Closure $next)
    {
        // If there isn't an ID on the provided token, throw exception.
        if (! $this->token->id) {
            throw new AccessDeniedHttpException('A user must be logged-in to do that.');
        }

        return $next($request);
    }
403529
public function changePasswordAction(Request $request)
    {
        $user = $this->getUser();
        if (!is_object($user) || !$user instanceof UserInterface) {
            throw new AccessDeniedException('This user does not have access to this section.');
        }

        /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
        $dispatcher = $this->get('event_dispatcher');

        $event = new GetResponseUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->get('fos_user.change_password.form.factory');

        $form = $formFactory->createForm();
        $form->setData($user);

        $form->handleRequest($request);

        if ($form->isValid()) {
            /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
            $userManager = $this->get('fos_user.user_manager');

            $event = new FormEvent($form, $request);
            $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event);

            $userManager->updateUser($user);

            if (null === $response = $event->getResponse()) {
                $this->get('session')->getFlashBag()->add('message', array(
                    'type' => 'success',
                    'message' => 'The record has been updated successfully.',
                ));

                return new RedirectResponse($this->generateUrl('admin_user'));
            }

            $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

            return $response;
        }

        return $this->render('FOSUserBundle:ChangePassword:changePassword.html.twig', array(
            'form' => $form->createView()
        ));
    }