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