Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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