0
我正在使用Symfony2和FOSUserBundle。我想讓一個使用Doctrine ORM的用戶登錄。在控制器中手動生成身份驗證令牌並進行身份驗證
$user = $em->getRepository("InoUserBundle:User")->find(10);
// I want the security context as $user
我正在使用Symfony2和FOSUserBundle。我想讓一個使用Doctrine ORM的用戶登錄。在控制器中手動生成身份驗證令牌並進行身份驗證
$user = $em->getRepository("InoUserBundle:User")->find(10);
// I want the security context as $user
像這樣:
$token = new UsernamePasswordToken($user, '12345', "admin", $user->getRolesAsArray());
$this->get('security.context')->setToken($token);
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
謝謝。什麼是「InteractiveLoginEvent」?登錄事件需要 – Mohebifar
,這可以確保登錄事件的所有事件偵聽器都是tirggerd – Rufinus