Skip to content

Instantly share code, notes, and snippets.

@chihiro-adachi
Created February 21, 2019 08:44
Show Gist options
  • Save chihiro-adachi/1d98c5b49a7848e3d03251dcf6b7d02c to your computer and use it in GitHub Desktop.
Save chihiro-adachi/1d98c5b49a7848e3d03251dcf6b7d02c to your computer and use it in GitHub Desktop.
イベントリスナ
<?php
namespace Eccube\EventListener;
use Eccube\Entity\Customer;
use Eccube\Request\Context;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LoginEventListeiner implements EventSubscriberInterface
{
/**
* @var Context
*/
private $context;
public function __construct(Context $context)
{
$this->context = $context;
}
public function onPasswordChange(GetResponseEvent $event)
{
if ($event->isMasterRequest()) {
$Customer = $this->context->getCurrentUser();
if ($Customer instanceof Customer) {
// パスワードの有効期限をチェック後、切れていたらパスワード変更画面へリダイレクト
$event->setResponse(new RedirectResponse('/change_password'));
}
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'onPasswordChange',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment