2013-01-13 34 views
2

注册后,我保证用户登录如下:触发认证成功事件

$token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles()); 
$this->get('security.context')->setToken($token); 

和希望,这也将引发我的成功处理程序:

$this->get('event_dispatcher')->dispatch(
    AuthenticationEvents::AUTHENTICATION_SUCCESS, 
    new AuthenticationEvent($token) 
); 

处理程序在安全配置中的标准表单登录中设置,例如

firewalls: 
    secured_area: 
     form_login: 
      success_handler: authentication_handler 

成功处理程序在登录时触发正常但注册后未触发。

这只是一个配置问题?和/或所有这些都可以通过单个事件来实现?

回答

0

我认为你必须认证用户触发事件:

$token = $this->get('my.bundle.authentication.manager')->authenticate(new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles())); 
$this->get('security.context')->setToken($token); 

my.bundle.authentication.manager将是security.authentication.manager一个别名,它可能是这样注册(XML):

<service id="my.bundle.authentication.manager" alias="security.authentication.manager" />