EC-CUBE4でログインしたときに何かする方法です。
まずCusotomizeディレクトリ内にEventSubscriberディレクトリを設置してください。
次に以下のようにAuthenticationSuccessSubscriber.phpを作成してEventSubscriber内に設置してください。
<?php
namespace Customize\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\AuthenticationEvents;
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
/**
* ログインしたときに何かする
*
* @author Akira Kurozumi <info@a-zumi.net>
*/
class AuthenticationSuccessSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents(): array
{
return [
AuthenticationEvents::AUTHENTICATION_SUCCESS => "onAuthenticationSuccess"
];
}
public function onAuthenticationSuccess(AuthenticationEvent $event)
{
$token = $event->getAuthenticationToken();
if(!$token->getRoles()) {
return;
}
switch($token->getProviderKey()) {
case "customer":
// 会員がログインしたときに何かする
var_dump("customer");
$User = $token->getUser();
break;
case "admin":
// メンバーがログインしたときに何かする
var_dump("admin");
$User = $token->getUser();
break;
}
}
}
以上で完成です。
これで会員またはメンバーがログインしたときにメール通知などの何かしらの処理が追加できます。
