public function enforceOwnerSecurity(Event $event) { $user = $this->getUser(); if ($user != $event->getOwner()) { throw $this->createAccessDeniedException('You are not the owner!!!'); } }
public function enforceOwnerSecurity(Event $event) { $user = $this->getUser(); if ($user != $event->getOwner()) { throw new AccessDeniedException('You do not own this!'); } }
public function enforceOwnerSecurity(Event $event) { $user = $this->getUser(); if ($user != $event->getOwner()) { // if you're using 2.5 or higher // throw $this->createAccessDeniedException('You are not the owner!!!'); throw new AccessDeniedException('You are not the owner!!!'); } }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $event1 = new Event(); $event1->setName('Darth\'s surprise birthday party!'); $event1->setLocation('Deathstar'); $event1->setTime(new \DateTime('tomorrow noon')); $event1->setDetails('Darth HATES surprises!!'); $manager->persist($event1); $event2 = new Event(); $event2->setName('Rebellion Fundraiser Bake Sale!'); $event2->setLocation('Endor'); $event2->setTime(new \DateTime('Thursday noon')); $event2->setDetails('Ewok pies! Support the rebellion!'); $manager->persist($event2); $manager->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $user = $this->getReference('user-user'); $event1 = new Event(); $event1->setName('Darth\'s Birthday Party!'); $event1->setLocation('Deathstar'); $event1->setTime(new \DateTime('yesterday noon')); $event1->setDetails('Ha! Darth HATES surprises!!!'); $event1->setOwner($user); $manager->persist($event1); $event2 = new Event(); $event2->setName('Rebellion Fundraiser Bake Sale!'); $event2->setLocation('Endor'); $event2->setTime(new \DateTime('Thursday noon')); $event2->setDetails('Ewok pies! Support the rebellion!'); $event2->setOwner($user); $manager->persist($event2); // the queries aren't done until now $manager->flush(); }
public function load(ObjectManager $manager) { $user = $manager->getRepository("YodaUserBundle:User")->findOneByUsernameOrEmail('user'); $event1 = new Event(); $event1->setName('Darth\'s Birthday Party!'); $event1->setLocation('Deathstar'); $event1->setTime(new \DateTime('tomorrow noon')); $event1->setOwner($user); $event1->setDetails('Ha! Darth HATES surprises!!!'); $manager->persist($event1); $event2 = new Event(); $event2->setName('Rebellion Fundraiser Bake Sale!'); $event2->setLocation('Endor'); $event2->setOwner($user); $event2->setTime(new \DateTime('Thursday noon')); $event2->setDetails('Ewok pies! Support the rebellion!'); $manager->persist($event2); // the queries aren't done until now $manager->flush(); }
public function load(ObjectManager $manager) { $event1 = new Event(); $event1->setName('Darth\'s Birthday Party!'); $event1->setLocation('Deathstar'); $event1->setTime(new \DateTime('tomorrow noon')); $event1->setDetails('Ha! Darth HATES surprises!!!'); $manager->persist($event1); $event3 = new Event(); $event3->setName('Asia 2015 Symfony conference'); $event3->setLocation('Beijing'); $event3->setTime(new \DateTime('Thursday noon')); $event3->setDetails('Everybody who want to talk about symfony 2 framework'); $manager->persist($event3); // the queries aren't done until now $manager->flush(); }
public function load(ObjectManager $manager) { $event1 = new Event(); $event1->setName('My first event'); $event1->setLocation('Waddesdon'); //$event1->setTime(new \DateTime('tomorrownoon')); $event1->setTime(new \DateTime('tomorrow noon')); $event1->setDetails('He will love this!'); $manager->persist($event1); $event2 = new Event(); $event2->setName('My Second event'); $event2->setLocation('Quatin'); // $event2->setTime(new \DateTime('tomorrowlunchtime')); $event2->setTime(new \DateTime('tomorrow noon')); $event2->setDetails('He will hate this!'); $manager->persist($event2); $manager->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $wayne = $manager->getRepository('UserBundle:User')->findOneByUsernameOrEmail('wayne'); $event1 = new Event(); $event1->setName('some event name'); $event1->setLocation('some location'); $event1->setTime(new \DateTime('tomorrow noon')); $event1->setDetails('some details to the event'); $manager->persist($event1); $event2 = new Event(); $event2->setName('event 2'); $event2->setLocation('location 2'); $event2->setTime(new \DateTime('Thursday noon')); $event2->setDetails('some details to the event'); $manager->persist($event2); $event1->setOwner($wayne); $event2->setOwner($wayne); $manager->flush(); }
/** * @param Event $event * @param string $format * @return \Symfony\Component\HttpFoundation\Response */ private function createAttendingResponse(Event $event, $format) { if ($format == 'json') { $data = array('attending' => $event->hasAttendee($this->getUser())); $response = new JsonResponse($data); return $response; } $url = $this->generateUrl('event_show', array('slug' => $event->getSlug())); return $this->redirect($url); }
/** * Simple function to enforce security - should be abstracted into a voter * Simple function to enforce security - should be abstracted into a voter * * @param Event $event * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ private function checkOwnerSecurity(Event $event) { $user = $this->getUser(); if ($this->get('security.context')->isGranted('ROLE_ADMIN')) { return; } if ($user == $event->getOwner()) { return; } throw new AccessDeniedException('You are not the owner!!!'); }
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = (require_once __DIR__ . '/app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->boot(); $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', $request); use Yoda\EventBundle\Entity\Event; $event = new Event(); $event->setName('Darth\'s surprise birthday party!'); $event->setLocation('Deathstar'); $event->setTime(new \DateTime('tomorrow noon')); //$event->setDetails('Ha! Darth HATES you'); $em = $container->get('doctrine')->getManager(); $em->persist($event); $em->flush();
/** * @param Event $event */ private function checkOwnerSecurity(Event $event) { $user = $this->getSecurityContext()->getToken()->getUser(); if ($user != $event->getOwner()) { throw new AccessDeniedException('You are not the owner!!!'); } }
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = (require_once __DIR__ . '/app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->boot(); $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', $request); use Yoda\EventBundle\Entity\Event; $event = new Event(); $event->setName('some event name'); $event->setLocation('some location'); $event->setTime(new \DateTime('tomorrow noon')); //$event->setDetails('some details to the event'); $em = $container->get('doctrine')->getManager(); $em->persist($event); $em->flush();
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; umask(00); $loader = (require_once __DIR__ . '/app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->boot(); $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', $request); // all our setup is done!!!!!! use Yoda\EventBundle\Entity\Event; $event = new Event(); $event->setName('Darth\'s surprise birthday party'); $event->setLocation('Deathstar'); $event->setTime(new \DateTime('tomorrow noon')); $event->setDetails('Ha! Darth HATES surprises!!!!'); $em = $container->get('doctrine')->getManager(); $em->persist($event); $em->flush();
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = (require_once __DIR__ . '/app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->boot(); $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', $request); //$templating = $container->get('templating'); // //echo $templating->render( // 'EventBundle:Default:index.html.twig', // array( // 'name'=>'Vader', // 'count'=>3 // ) //); use Yoda\EventBundle\Entity\Event; $event = new Event(); $event->setName('Darth\'s surprise birthday party!'); $event->setLocation('Dearth Star'); $event->setTime(new \DateTime('tomorrow noon')); $event->setDetails('Ha he will hate this'); $em = $container->get('doctrine')->getManager(); $em->persist($event); $em->flush();
private function checkOwnerSecurity(Event $event) { if ($this->getUser() != $event->getOwner()) { throw new AccessDeniedException('Not the owner'); } }
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = (require_once __DIR__ . '/app/bootstrap.php.cache'); Debug::enable(); require_once __DIR__ . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $kernel->boot(); $container = $kernel->getContainer(); $container->enterScope('request'); $container->set('request', $request); /* // Template $templating = $container->get('templating'); echo $templating->render( 'EventBundle:Default:index.html.twig', array('name' => 'Fabian Vallejos') ); */ use Yoda\EventBundle\Entity\Event; $event = new Event(); $event->setName('Fabian\'s new post!'); $event->setLocation('fabianvallejos.com'); $event->setTime(new \DateTime('today')); //$event->setDetails('An hack to quickly debug Symfony2 apps'); $em = $container->get('doctrine')->getManager(); $em->persist($event); $em->flush();
/** * Creates a form to delete a Event entity. * * @param Event $event The Event entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Event $event) { return $this->createFormBuilder()->setAction($this->generateUrl('event_delete', array('id' => $event->getId())))->setMethod('DELETE')->getForm(); }
private function checkCapacity(Event $event) { if ($this->getUser() != $event->getOwner()) { throw $this->createAccessDeniedException('You are not owner, you could not change this event !'); } }