在symfony2上通过AJAX验证用户?

时间:2013-01-15 22:26:43

标签: symfony

我通过ajax调用此脚本:

$userRepository = $this->getDoctrine( )->getRepository( 'DonePunctisBundle:User' );
$user           = $userRepository->findOneByUsername( array( 'username' => $fbuser['email'] ) );

$this->_authenticateUser($user);


protected function _authenticateUser( User $user )  {
    $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles() );
    $this->get( 'security.context' )->setToken( $token );
}

没有错误,但用户没有登录。我需要做什么?

1 个答案:

答案 0 :(得分:0)

只需在UsernamePasswordToken中传递用户密码。

new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());