symfony2 の FOS ユーザー バンドルを使用しており、カスタム コードを実行して、ユーザーが登録を確認したときにイベントをログに記録したいと考えています。/register/confirm/{token}
ただ、ユーザー確定時のイベントはないようなので、ユーザーアカウント確定時の実行にフックする最適な方法を教えていただきたいです。
symfony2 の FOS ユーザー バンドルを使用しており、カスタム コードを実行して、ユーザーが登録を確認したときにイベントをログに記録したいと考えています。/register/confirm/{token}
ただ、ユーザー確定時のイベントはないようなので、ユーザーアカウント確定時の実行にフックする最適な方法を教えていただきたいです。
RegistrationController (ドキュメントを参照) をオーバーライドして、ログ機能を追加できます。
dev-master (2.0.*@dev) を使用できる場合は、FOSUserBundle で新しいコントローラー イベントを使用できます。詳細については、github のドキュメントを参照してください: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/controller_events.md
これは確認イベントの小さな例です。上記のリンクに記載されているように、サービスを定義することを忘れないでください。
<?php
namespace Acme\UserBundle\Security\Listener;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RegistrationListener implements EventSubscriberInterface
{
public function __construct(/** inject services you need **/)
{
// assign services to private fields
}
public static function getSubscribedEvents()
{
return array(FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',);
}
/**
* GetResponseUserEvent gives you access to the user object
**/
public function onRegistrationConfirm(GetResponseUserEvent $event)
{
// do your stuff
}
}