示例#1
0
 /**
  * @return Client
  */
 public function toClient()
 {
     $name = $this->getClientName();
     $hasName = $name !== null && strlen($name) > 0;
     $grantTypes = $this->getGrantTypes();
     $clientUri = $this->getClientUri();
     $tosUri = $this->getTosUri();
     $clientName = $this->getClientName();
     $redirectUris = $this->getRedirectUris();
     $client = new Client();
     if ($grantTypes) {
         $client->setAllowedGrantTypes($grantTypes);
     }
     if ($clientUri) {
         $client->setLandingPageUrl($clientUri)->setSiteUrl($clientUri);
     }
     if ($tosUri) {
         $client->setTermsOfUseUrl($tosUri);
     }
     if ($clientName) {
         $client->setName($clientName);
     }
     if ($redirectUris) {
         $client->setRedirectUris($redirectUris);
     }
     $client->setVisible($hasName)->setPublished(false);
     return $client;
 }
 /**
  * @Route("/edit/{id}", name="lc_dev_shout_edit")
  * @Template()
  */
 public function editAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $client = $em->getRepository('PROCERGSOAuthBundle:Client')->findOneOwned($this->getUser(), $id);
     if (!$client) {
         return $this->redirect($this->generateUrl('lc_dev_shout_new'));
     }
     $form = $this->createForm('procergs_logincidadao.client.base.form.type', $client);
     $form->handleRequest($request);
     $messages = '';
     if ($form->isValid()) {
         $client->setAllowedGrantTypes(Client::getAllGrants());
         $clientManager = $this->container->get('fos_oauth_server.client_manager');
         $clientManager->updateClient($client);
         $messages = 'aeee';
     }
     return $this->render('PROCERGSLoginCidadaoCoreBundle:Dev\\Client:new.html.twig', array('form' => $form->createView(), 'client' => $client, 'messages' => $messages));
 }
 /**
  * @Route("/populate/{id}", name="lc_admin_app_populate")
  * @Template()
  */
 public function populateAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $clientManager = $this->container->get('fos_oauth_server.client_manager');
     $em->beginTransaction();
     $input = 'Lorem Ipsum ';
     $person = $em->getRepository('PROCERGSLoginCidadaoCoreBundle:Person')->find($id);
     foreach (range(1, 1) as $val1) {
         $client = new Client();
         $client->setPerson($person);
         $client->setName("Sample client {$val1} " . uniqid());
         $client->setDescription('Sample client');
         $client->setSiteUrl("http://localhost");
         $client->setRedirectUris(array('http://localhost'));
         $client->setLandingPageUrl('http://localhost');
         $client->setTermsOfUseUrl('http://localhost');
         $client->setAllowedGrantTypes(Client::getAllGrants());
         $client->setPublished(0);
         $client->setVisible(0);
         $clientManager->updateClient($client);
         $list = array();
         foreach (range(1, 20) as $val2) {
             $cm = "Sample category {$val2} ";
             $category = new Category();
             $category->setClient($client);
             $category->setName($cm . uniqid());
             $category->setDefaultIcon('glyphicon glyphicon-envelope');
             $category->setDefaultTitle($cm . " title");
             $category->setDefaultShortText($cm . " shorttext");
             $category->setMailTemplate("%title%\r\n%shorttext%\r\n");
             $category->setMailSenderAddress($person->getEmail());
             $category->setEmailable(true);
             $category->setMarkdownTemplate("%title%\r\n--\r\n\r\n> %shorttext%\r\n\r\n");
             $category->setHtmlTemplate(MarkdownExtra::defaultTransform($category->getMarkdownTemplate()));
             $em->persist($category);
             foreach (range(1, 20) as $val3) {
                 $r = rand(1, 19);
                 $msg = array();
                 if ($r % 2) {
                     $msg['title'] = str_repeat($input, $r);
                     $msg['shorttext'] = str_repeat($input, $r);
                 }
                 $not = new Notification();
                 $not->setPerson($person);
                 $not->setCategory($category);
                 $not->setIcon($category->getDefaultIcon());
                 $not->setTitle(isset($msg['title']) ? $msg['title'] : $category->getDefaultTitle());
                 $not->setShortText(isset($msg['shorttext']) ? $msg['shorttext'] : $category->getDefaultShortText());
                 $not->parseHtmlTemplate($category->getHtmlTemplate());
                 $em->persist($not);
                 $list[] =& $not;
             }
             $list[] =& $category;
         }
         $em->flush();
         $em->clear($client);
         foreach ($list as &$entityes) {
             $em->clear($entityes);
         }
     }
     $em->commit();
     return new Response("ok");
 }
 /**
  * @Route("/{id}/edit", name="lc_dev_client_edit")
  * @Template()
  */
 public function editAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $client = $em->getRepository('PROCERGSOAuthBundle:Client')->createQueryBuilder('c')->where(':person MEMBER OF c.owners')->andWhere('c.id = :id')->setParameters(array('id' => $id, 'person' => $this->getUser()))->getQuery()->getOneOrNullResult();
     if (!$client) {
         return $this->redirect($this->generateUrl('lc_dev_client_new'));
     }
     $form = $this->get('form.factory')->create($this->get('procergs_logincidadao.client.base.form.type'), $client);
     $form->handleRequest($request);
     $messages = '';
     if ($form->isValid()) {
         $metadata = $form->get('metadata')->getData();
         $client->setAllowedGrantTypes(Client::getAllGrants());
         $client->setMetadata($metadata);
         $metadata->setClient($client);
         $clientManager = $this->container->get('fos_oauth_server.client_manager');
         $clientManager->updateClient($client);
         $translator = $this->get('translator');
         $this->get('session')->getFlashBag()->add('success', $translator->trans('Updated successfully!'));
         return $this->redirectToRoute('lc_dev_client_edit', compact('id'));
     }
     return $this->render('PROCERGSLoginCidadaoCoreBundle:Dev\\Client:new.html.twig', array('form' => $form->createView(), 'client' => $client, 'messages' => $messages));
 }
示例#5
0
 /**
  * @param Client $client
  * @return array
  */
 public function getClientScope(Client $client)
 {
     $authorizations = $this->getAuthorizations();
     foreach ($authorizations as $auth) {
         $c = $auth->getClient();
         if ($c->getId() == $client->getId()) {
             return $auth->getScope();
         }
     }
     return null;
 }
 private function checkRegistrationAccessToken(Request $request, Client $client)
 {
     $raw = $request->get('access_token', $request->headers->get('authorization'));
     $token = str_replace('Bearer ', '', $raw);
     $metadata = $client->getMetadata();
     if (!$token || $metadata->getRegistrationAccessToken() !== $token) {
         throw $this->createAccessDeniedException();
     }
 }
示例#7
0
 /**
  * Checks if a given Client can access this Person's specified scope.
  * @param \PROCERGS\OAuthBundle\Entity\Client $client
  * @param mixed $scope can be a single scope or an array with several.
  * @return boolean
  */
 public function isAuthorizedClient(Client $client, $scope)
 {
     $authorizations = $this->getAuthorizations();
     foreach ($authorizations as $auth) {
         $c = $auth->getClient();
         if ($c->getId() == $client->getId()) {
             return $auth->hasScopes($scope);
         }
     }
     return false;
 }
 public function lcClientPictureWebPath($var)
 {
     return Client::resolvePictureWebPath($var);
 }