注册后以编程方式登录symfony2

时间:2012-07-13 15:39:51

标签: symfony

我尝试使用此代码注册后手动登录用户:

http://www.michelsalib.com/2011/04/pragmatically-authenticate-the-user-in-symfony2/

它不与新创建的用户合作,但是当我在用户注册后登录其他现有用户时,一切正常。 我认为用户对象不完整,但我试图再次阅读registrerd用户,但它也不起作用。

有谁知道问题是什么?

非常感谢

1 个答案:

答案 0 :(得分:2)

您必须创建一个新令牌并将其传递给安全上下文。

// Create a new token
$token = new UsernamePasswordToken($user, $credentials, $providerKey, $user->getRoles());

// Retrieve the security context and set the token
$context = $this->container->get('security.context');
$context->setToken($token);
相关问题