Symfony2 (FOSUserBundle을 사용하지 않음)에서 내 자신의 사용자 관리 시스템을 구축 중이며 강제로 사용자가 비밀번호를 변경하도록하고 싶습니다.Symfony2 - 내장 된 요청 이벤트를 무시하면서 dev 모드에서 요청 EventListener의 응답 리디렉션
kernal.request
이벤트를 수신하도록 EventListener를 설정 한 다음 수신기에서 사용자가 암호를 변경해야하는지 여부를 결정하기 위해 일부 논리를 수행합니다. 암호가 변경되면 "암호 변경"경로로 리디렉션됩니다.
은 내가 kernal.request
에서 수신하도록 내 config.yml
에 서비스를 추가 :
password_change_listener:
class: Acme\AdminBundle\EventListener\PasswordChangeListener
arguments: [ @service_container ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onMustChangepasswordEvent }
그리고 청취자 :
public function onMustChangepasswordEvent(GetResponseEvent $event) {
$securityContext = $this->container->get('security.context');
// if not logged in, no need to change password
if (!$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'))
return;
// If already on the change_password page, no need to change password
$changePasswordRoute = 'change_password';
$_route = $event->getRequest()->get('_route');
if ($changePasswordRoute == $_route)
return;
// Check the user object to see if user needs to change password
$user = $this->getUser();
if (!$user->getMustChangePassword())
return;
// If still here, redirect to the change password page
$url = $this->container->get('router')->generate($changePasswordRoute);
$response = new RedirectResponse($url);
$event->setResponse($response);
}
오전 데 문제가 개발자 모드에서, 내 청취자가 있다는 것이다 또한 프로파일 바 및 assetic 요청 이벤트를 리디렉션합니다. 애셋을 덤프하고 캐시를 지우고 프로덕션 모드에서 사이트를 볼 때 작동합니다.
assetic/profiler bar/다른 내부 컨트롤러의 이벤트를 무시할 수있는 방법이 있습니까? 또는 사용자를 change_password 페이지로 리디렉션하는 더 좋은 방법입니다 (로그인 성공뿐만 아니라)?
야생 해킹 솔루션을 생각해 보려고하지만 Symfony2에서이를 우아하게 처리 할 수있는 방법이 있습니까?