Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Forked from johnriberto/gist:b907877e1bb18423bd4ed68d273f152a
Last active August 23, 2017 17:21
Show Gist options
  • Save tarlepp/476b8edd65019b4a3d20c6511a408249 to your computer and use it in GitHub Desktop.
Save tarlepp/476b8edd65019b4a3d20c6511a408249 to your computer and use it in GitHub Desktop.
<?php
class FooController
{
public function indexAction(Request $request, UserData $userDataService): Response
{
$username = 'someuser';
$foo = $userDataService->checkUser($username);
if ($foo instanceof Response) {
return $foo;
}
....
}
}
services:
AppBundle\Security\UserData:
class: AppBundle\Security\UserData
arguments: ['@doctrine.orm.entity_manager']
<?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