Forked from johnriberto/gist:b907877e1bb18423bd4ed68d273f152a
Last active
August 23, 2017 17:21
-
-
Save tarlepp/476b8edd65019b4a3d20c6511a408249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FooController | |
{ | |
public function indexAction(Request $request, UserData $userDataService): Response | |
{ | |
$username = 'someuser'; | |
$foo = $userDataService->checkUser($username); | |
if ($foo instanceof Response) { | |
return $foo; | |
} | |
.... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
AppBundle\Security\UserData: | |
class: AppBundle\Security\UserData | |
arguments: ['@doctrine.orm.entity_manager'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Security; | |
use Doctrine\ORM\EntityManagerInterface; | |
use Symfony\Component\HttpFoundation\RedirectResponse; | |
class UserData | |
{ | |
private $entityManager; | |
public function __construct(EntityManagerInterface $entityManager) | |
{ | |
$this->entityManager = $entityManager; | |
} | |
public function checkUser($username) | |
{ | |
$user = $this->entityManager->getRepository('AppBundle:User')->findOneBy(['username' => $username]); | |
if ($user) { | |
$camp = $this->entityManager->getRepository('AppBundle:Campaigns')->findOneBy(['id' => $user->getTarget()]); | |
if ($camp) { | |
// redirect | |
return new return new RedirectResponse('https://www.facebook.com', 301); | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment