1

このコードで登録した後、手動でユーザーにログインしようとしています:

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

新しく作成したユーザーでは機能しませんが、ユーザー登録後に他の既存のユーザーにログインすると、すべて正常に機能します。ユーザーオブジェクトが完全ではないと思いましたが、registrerdユーザーをもう一度読み取ろうとしましたが、機能しません。

誰かが問題が何であるかについての考えを持っていますか?

どうもありがとうございます

4

1 に答える 1

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);
于 2012-07-13T15:48:22.067 に答える