我使用的Symfony2的FOS用戶捆綁,並希望運行一些自定義代碼來記錄事件,當用戶確認他在/register/confirm/{token}
Symfony2 - 有沒有辦法掛鉤到用戶確認事件?
登記然而,似乎沒有成爲當用戶是一個事件已確認,所以我想知道確認用戶帳戶時執行的最佳方式。
我使用的Symfony2的FOS用戶捆綁,並希望運行一些自定義代碼來記錄事件,當用戶確認他在/register/confirm/{token}
Symfony2 - 有沒有辦法掛鉤到用戶確認事件?
登記然而,似乎沒有成爲當用戶是一個事件已確認,所以我想知道確認用戶帳戶時執行的最佳方式。
您可以覆蓋RegistrationController(請參閱doc)以添加日誌記錄功能。
如果您可以使用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
}
}