public function contactSendAction(Request $request)
 {
     $contact = $request->get('email');
     $message = \Swift_Message::newInstance()->setSubject('CONSULTA WEB')->setFrom($contact['userEmail'], $contact['name'])->setTo('*****@*****.**')->setBody($contact['body'], 'text/html');
     $this->get('mailer')->send($message);
     return JsonResponse::create(array());
 }
Example #2
0
 public function getTagAction(Request $request)
 {
     $q = $request->get('q');
     $em = $this->getDoctrine()->getManager();
     $result = $em->getRepository('AcmeBlogBundle:Tag')->findTagsByName($q);
     return JsonResponse::create($result);
 }
 public function obtenerDatosPanillaNormal($central_id, $planilla_id)
 {
     $planilla = Planilla::find($planilla_id);
     $planilla['tipo'] = 'normal';
     $planilla->load('viaje.conductor', 'central.ciudad.departamento');
     return JsonResponse::create($planilla);
 }
Example #4
0
 public function testCreate()
 {
     $response = JsonResponse::create(array('foo' => 'bar'), 204);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response);
     $this->assertEquals('{"foo":"bar"}', $response->getContent());
     $this->assertEquals(204, $response->getStatusCode());
 }
Example #5
0
 public function wrapResponse($response)
 {
     if (!$response instanceof Response) {
         $response = is_scalar($response) ? Response::create($response) : JsonResponse::create($response);
     }
     return $response;
 }
 public function __invoke(\Exception $e, $code)
 {
     $error = array("code" => $e->getCode(), "message" => $e->getMessage());
     if ($this->app["debug"]) {
         $error["trace"] = $e->getTraceAsString();
     }
     return JsonResponse::create($error);
 }
 /**
  * @param Request $request
  *   The request that resulted in an AuthenticationException
  *
  * @param AuthenticationException $authException
  *   The exception that started the authentication process
  *
  * @return Response
  */
 public function start(Request $request, AuthenticationException $authException = null)
 {
     $responseData = ['error' => 'Unauthorized'];
     if (!is_null($authException)) {
         $responseData['details'] = $authException->getMessage();
     }
     return JsonResponse::create($responseData, 401);
 }
 public function testHandlingNonIlluminateResponseErrorResponses()
 {
     $response = JsonResponse::create(['format' => 'json'], 500);
     $formatted = $this->formatter->formatResult($response);
     $this->assertJsonResponse($formatted, 500);
     $response = Response::create('<html>', 500);
     $formatted = $this->formatter->formatResult($response);
     $this->assertNormalResponse($formatted, 500);
 }
Example #9
0
 /**
  * @Route("/stationstate")
  * @Method("GET")
  */
 public function stationStateAction()
 {
     $repository = $this->getDoctrine()->getRepository('StationMapping:StationState');
     $data = $repository->findLastSnapshot();
     return JsonResponse::create(array_map(function (StationState $stationState) {
         $station = $stationState->getStation();
         return array('name' => $station->getName(), 'id' => $station->getId(), 'statusCode' => $stationState->getStatusCode(), 'availableBikes' => $stationState->getAvailableBikes(), 'freeSlots' => $stationState->getFreeSlots(), 'latitude' => $station->getLatitude(), 'longitude' => $station->getLongitude());
     }, $data));
 }
 /**
  * @param $id
  * @return Response
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  * @ApiDoc(
  *                                                    resource=true,
  *                                                    description="get user by id"
  *                                                    )
  * @Get("/public/user/get/{id}", defaults={"id" = null})
  */
 public function getUserByIdAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $em->find('OjsUserBundle:User', $id);
     if ($user) {
         return JsonResponse::create(['id' => $id, 'text' => $user->getUsername() . " <" . $user->getEmail() . '>']);
     }
     throw new NotFoundHttpException();
 }
 public function connect(Application $app)
 {
     // Creates a new controller based on the default route
     $controllers = $app['controllers_factory'];
     $controllers->post('/json', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsJsonLD(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/csv', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsCSV(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/ooxml', function (Request $request, Application $app) {
         if ($request->request->has('email')) {
             $email = new EmailAddress($request->request->get('email'));
         } else {
             $email = null;
         }
         $selection = $request->request->get('selection');
         $include = $request->request->get('include');
         $command = new ExportEventsAsOOXML(new EventExportQuery($request->request->get('query')), $email, $selection, $include);
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     $controllers->post('/pdf', function (Request $request, Application $app) {
         $deserializer = new ExportEventsAsPDFJSONDeserializer();
         $command = $deserializer->deserialize(new String($request->getContent()));
         /** @var \Broadway\CommandHandling\CommandBusInterface $commandBus */
         $commandBus = $app['event_command_bus'];
         $commandId = $commandBus->dispatch($command);
         return JsonResponse::create(['commandId' => $commandId]);
     });
     return $controllers;
 }
 public function handle(Request $request)
 {
     // Fetch client_id from authenticated token.
     $clientId = $this->checkClientId();
     // Check refresh_token, then fetch username and scope.
     list($username, $scope) = $this->checkRefreshToken($request, $clientId);
     // Generate access_token, store to backend and set token response.
     $parameters = $this->tokenTypeHandlerFactory->getTokenTypeHandler()->createAccessToken($clientId, $username, $scope);
     return JsonResponse::create($parameters, 200, ['Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
 }
Example #13
0
 public function setStatusAjaxAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $objLoan = $em->getRepository('DataBundle:Loan')->find($request->get('id'));
     $status = (int) $request->get('status');
     /* @var $objLoan \DataBundle\Entity\Loan */
     $objLoan->setStatus($status);
     $em->flush();
     return \Symfony\Component\HttpFoundation\JsonResponse::create(array('status' => 'success', 'new_status_label' => $objLoan->getStatusLabel(), 'message' => 'Pożyczka o ID równym ' . $objLoan->getId() . ' zmieniła status na ' . $objLoan->getStatusLabel()));
 }
 /**
  * Action for route /markpostunread/searchunread
  *
  * Returns the text for the 'Unread posts' search link in JSON
  */
 public function searchunread()
 {
     // Don't allow usage if default behaviour is selected
     if ($this->core->cfg('unread_posts_link') == 0) {
         throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
     }
     $response = array('search_unread' => $this->core->get_search_unread_text());
     $headers = array('Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'Expires' => '0');
     return JsonResponse::create($response, 200, $headers);
 }
 /**
  * @return JsonResponse
  */
 public function getUser()
 {
     $user = null;
     $minimalUserInfo = $this->userSessionService->getMinimalUserInfo();
     if (is_null($minimalUserInfo)) {
         return new Response('No active user.', Response::HTTP_NOT_FOUND);
     }
     $user = $this->userService->getUser($minimalUserInfo->getId());
     return JsonResponse::create()->setData($user)->setPrivate();
 }
 public function __invoke(Application $app, Request $request, $id)
 {
     $requestJson = $request->getContent() ?: "{}";
     $data = json_decode($requestJson);
     $this->validate($app, $id, $data);
     $isCreated = !$this->service->contains($request->getRequestUri());
     if ($this->service->save($request->getRequestUri(), $data) === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to save resource");
     }
     return JsonResponse::create($data, $isCreated ? Response::HTTP_CREATED : Response::HTTP_OK);
 }
 public function debugAction(Request $request)
 {
     // Fetch authenticated access token from security context.
     $token = $this->tokenStorage->getToken();
     if ($token === null || !$token instanceof AccessTokenToken) {
         throw new ServerErrorException(['error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.']);
     }
     // Handle debug endpoint response.
     $parameters = ['access_token' => $token->getAccessToken(), 'token_type' => $token->getTokenType(), 'client_id' => $token->getClientId(), 'username' => $token->getUsername(), 'expires' => $token->getExpires()->getTimestamp(), 'scope' => $token->getScope()];
     return JsonResponse::create($parameters, 200, ['Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
 }
 public function duplicateAction(Request $request, $id, $_format)
 {
     // TODO: tout ca factorised !
     switch ($_format) {
         case 'jsonp':
         case 'json':
             return JsonResponse::create(['status' => true, 'id' => $id], 200, ['Content-Type' => 'application/json']);
         default:
             return $this->render('default/minimalist.html.twig', array('content' => $id . ' is now duplicated'));
     }
 }
 /**
  * @param  Request      $request
  * @return JsonResponse
  */
 public function logAction(Request $request)
 {
     if ($request->request->has('log')) {
         $data = $request->request->get('log');
         $log = new Log();
         $log->setTopic($data['topic'])->setValue($data['value']);
         $this->entityManager->persist($log);
         $this->entityManager->flush($log);
     }
     return JsonResponse::create();
 }
 public function citiesAction($country)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var Country $country */
     if (!($country = $em->getRepository('BulutYazilimLocationBundle:Country')->find($country))) {
         throw $this->createNotFoundException();
     }
     return JsonResponse::create($country->getProvinces()->map(function (Province $province) {
         return ['id' => $province->getId(), 'name' => $province->getName()];
     })->toArray());
 }
 public function handle(Request $request)
 {
     // Fetch client_id from authenticated token.
     $clientId = $this->checkClientId();
     // No (and not possible to have) username, set as empty string.
     $username = '';
     // Check and set scope.
     $scope = $this->checkScope($request, $clientId, $username);
     // Generate access_token, store to backend and set token response.
     $parameters = $this->tokenTypeHandlerFactory->getTokenTypeHandler()->createAccessToken($clientId, $username, $scope);
     return JsonResponse::create($parameters, 200, ['Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
 }
Example #22
0
 public function get($query)
 {
     if (is_string($query)) {
         $query = $this->query($query);
     }
     $this->db_columns = array_keys($query->first());
     $this->query = $query;
     $this->processed_query = $query;
     $data = $this->render();
     $output = array("iTotalRecords" => $this->count, "iTotalDisplayRecords" => $this->filtered, "aaData" => $data);
     return \Symfony\Component\HttpFoundation\JsonResponse::create($output);
 }
 public function __invoke(Application $app, Request $request)
 {
     $requestJson = $request->getContent() ?: "{}";
     $data = json_decode($requestJson);
     $data->id = $app["uniqid"];
     $this->validate($app, $data);
     $location = $app["url_generator"]->generate($this->schema, array("id" => $data->id));
     if ($this->service->save($location, $data) === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to save resource");
     }
     return JsonResponse::create($data, Response::HTTP_CREATED, array("Location" => $location));
 }
 public function __invoke(Request $request)
 {
     if (!$this->service->contains($request->getRequestUri())) {
         throw new NotFoundHttpException("Not Found");
     }
     $resource = $this->service->fetch($request->getRequestUri());
     if ($resource === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to retrieve resource");
     }
     $response = JsonResponse::create($resource);
     $response->headers->set("Content-Type", $this->contentType);
     return $response;
 }
Example #25
0
 public function onView(GetResponseForControllerResultEvent $event)
 {
     $result = $event->getControllerResult();
     if (is_object($result) && method_exists($result, 'toResponse')) {
         $response = $result->toResponse();
     } elseif (is_array($result)) {
         $response = JsonResponse::create($result);
     } else {
         $response = Response::create($result);
     }
     if ($response) {
         $event->setResponse($response);
     }
 }
 public function citiesAction($country)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var Country $country */
     $country = $em->getRepository('OkulBilisimLocationBundle:Country')->find($country);
     if (!$country) {
         throw $this->createNotFoundException();
     }
     $cities_array = [];
     foreach ($country->getProvinces() as $city) {
         $cities_array[] = ['id' => $city->getId(), 'name' => $city->getName()];
     }
     return JsonResponse::create($cities_array);
 }
 /**
  * @param  Request $request
  * @return mixed
  */
 public function providerAction(Request $request)
 {
     $repo = $this->getDoctrine()->getRepository('AppBundle:Client');
     $data = json_decode($request->getContent(), true);
     $client = $repo->find($data['clientId']);
     $params = array('code' => $data['code'], 'client_id' => $data['clientId'], 'redirect_uri' => $data['redirectUri'], 'grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_secret' => $client->getSecret());
     // Step 1. Exchange authorization code for access token.
     $subrequest = new Request($params, array(), array('_controller' => 'fos_oauth_server.controller.token:tokenAction'));
     $subresponse = $this->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
     $repo = $this->getDoctrine()->getRepository('AppBundle:AccessToken');
     $data = json_decode($subresponse->getContent(), true);
     $authCode = $repo->findOneByToken($data['access_token']);
     $jwtManager = $this->get('lexik_jwt_authentication.jwt_manager');
     return JsonResponse::create(array('token' => $jwtManager->create($authCode->getUser())));
 }
Example #28
0
 public function set()
 {
     $form = new \Colissimo\Form\FreeShipping($this->getRequest());
     $response = null;
     try {
         $vform = $this->validateForm($form);
         $data = $vform->get('freeshipping')->getData();
         $save = new ColissimoFreeshipping();
         $save->setActive(!empty($data))->save();
         $response = Response::create('');
     } catch (\Exception $e) {
         $response = JsonResponse::create(array("error" => $e->getMessage()), 500);
     }
     return $response;
 }
Example #29
0
 public function citiesAction(Request $request, $country)
 {
     if (!$request->isXmlHttpRequest()) {
         throw new NotFoundHttpException();
     }
     $em = $this->getDoctrine()->getManager();
     /** @var Country $country */
     $country = $em->getRepository('OjsLocationBundle:Country')->find($country);
     $this->throw404IfNotFound($country);
     $cities_array = [];
     foreach ($country->getProvinces() as $city) {
         $cities_array[] = ['id' => $city->getId(), 'name' => $city->getName()];
     }
     return JsonResponse::create($cities_array);
 }
 /**
  * @param Request     $request
  * @param Application $app
  *
  * @return string
  */
 public function contactAction(Request $request, Application $app)
 {
     $data = [];
     /** @var Form $form */
     $form = $app['form.factory']->createBuilder('form', $data, ['action' => $app['url_generator']->generate('contact'), 'method' => Request::METHOD_POST])->add('nombre', 'text', ['required' => false, 'label' => false, 'attr' => ['placeholder' => 'form.contacto.nombre.placeholder'], 'constraints' => [new NotBlank(['message' => 'form.contacto.nombre.notblank'])]])->add('apellidos', 'text', ['required' => false, 'label' => false, 'attr' => ['placeholder' => 'form.contacto.apellidos.placeholder']])->add('email', 'email', ['required' => false, 'label' => false, 'attr' => ['placeholder' => 'form.contacto.email.placeholder'], 'constraints' => [new NotBlank(['message' => 'form.contacto.email.notblank'])]])->add('mensaje', 'textarea', ['required' => false, 'label' => false, 'attr' => ['placeholder' => 'form.contacto.mensaje.placeholder', 'cols' => 30, 'rows' => 10], 'constraints' => [new NotBlank(['message' => 'form.contacto.mensaje.notblank'])]])->add('submit', 'submit', ['label' => 'form.contacto.submit', 'attr' => ['class' => 'btn']])->getForm();
     if ($request->isMethod(Request::METHOD_GET)) {
         return $app['twig']->render('contacto.html.twig', ['form' => $form->createView()]);
     }
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $message = \Swift_Message::newInstance()->setSubject('Contacto desde web "Promesa de la Virgen de Fatima"')->setFrom([$data['email'] => sprintf("%s %s", $data['nombre'], $data['apellidos'])])->setTo('*****@*****.**')->setBcc('*****@*****.**')->setBody($app['twig']->render('email/template.html.twig', ['data' => $data]), 'text/html');
         $app['mailer']->send($message);
         return JsonResponse::create(['alerta' => $app['twig']->render('alerta.html.twig', ['error' => !$form->isValid()]), 'form' => $app['twig']->render('form_contact.html.twig', ['form' => $form->createView()])], Response::HTTP_OK);
     }
     return JsonResponse::create(['alerta' => $app['twig']->render('alerta.html.twig', ['error' => !$form->isValid()]), 'form' => $app['twig']->render('form_contact.html.twig', ['form' => $form->createView()])], Response::HTTP_BAD_REQUEST);
 }