Skip to content

Instantly share code, notes, and snippets.

@danbower
Created January 2, 2015 21:30
Show Gist options
  • Save danbower/3dd39392f8b9ab15c0c1 to your computer and use it in GitHub Desktop.
Save danbower/3dd39392f8b9ab15c0c1 to your computer and use it in GitHub Desktop.
Manual login for symfony
public function manualLoginAction()
{
$user = $this->getDoctrine()->getRepository('UserBundle:User')->find(1);
$token = new UsernamePasswordToken($user, $user->getPassword(), 'admin_area', $user->getRoles());
$this->get('security.context')->setToken($token);
$request = $this->get('request');
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch('security.interactive_login', $event);
echo 'Logged in';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment