EC-CUBE4でログインしたら何かするプラグインを作る方法です。
まずは以下のコマンドでプラグインの雛形を作ります。
プラグインコードはなんでも良いのですが、今回は「InteractiveLogin」にしてください。
bin/console eccube:plugin:generate
ログインしたときに何かするためのイベント登録
ログイン後に何かするためには以下のように処理とイベント登録を行う必要があります。
自動生成されたプラグイン一式内にEventListenerディレクトリを作って、以下のSecurityListener.phpを設置して下さい。
<?php
namespace Plugin\InteractiveLogin\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
/**
* Description of SecurityListener
*
* @author Akira Kurozumi <info@a-zumi.net>
*/
class SecurityListener implements EventSubscriberInterface {
public static function getSubscribedEvents(): array
{
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];
}
/**
* ログインしたときに何かする
*
* @param InteractiveLoginEvent $event
*/
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
// ログインユーザーデータを取得
$User = $event
->getAuthenticationToken()
->getUser();
}
}
以上で完成です。
プラグインのインストールと有効化
プラグインのインストールと有効化を行うと動作します。
このプラグインのファイル一式はこちら。
