2012-08-12 2 views
4

, 내 사이트에, 어떻게 FOSUserBundle 및 Symfony2를 사용하여 다른 로그 아웃

을 생성, 로그인 한 사용자의 역할에 따라, 나는 로그 아웃은 두 개의 서로 다른 페이지에 교대로 리디렉션 할 수 있도록 할 . 퍼팅, 로그 아웃에서 모두 config.yml에서 수행되기 때문에,

<route id="fos_user_security_logout" pattern="/logout"> 
    <default key="_controller">FOSUserBundle:Security:logout</default> 
</route> 
<route id="fos_seller_security_logout" pattern="/logoutPremium"> 
    <default key="_controller">FOSUserBundle:Security:logoutPremium</default> 
</route> 

그러나 :

그래서,이 같은 싶지 :

{% if is_granted("ROLE_PREMIUM") %} 
    <a href="{{ path('fos_user_security_logout_premium') }}">{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}</a> 
{% else %} 
    <a href="{{ path('fos_user_security_logout') }}">{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}</a> 
{% endif %} 

을 그리고, 어떻게 든, 같은 것을 할 로그인과 로그 아웃에 관한이 모든 구성에서는 두 번째 트리거를 구성하고 구현하는 방법을 모르겠습니다. 사실 내가 원하는 것은 역할에 따라 사용자를 두 개의 다른 페이지로 리디렉션하는 것입니다. 나머지는 모두 동일하게 유지해야합니다.

여기에 넣을 내용은 무엇이든 security.yml에 넣으시겠습니까?

 logout: 
      path: /logout 
      target: /main/user 

덕분에 많은

+0

하나의 방법입니다 볼 때 사용자가 프리미엄 회원인지 여부를 나타내는 사용자가 로그인. 그리고 사용자가 로그 아웃했을 때, 템플릿이 참인 경우 템플릿을 체크인하고, 프리미엄 로그 아웃을 위해 html을 렌더링하고 그렇지 않으면 정상적인 로그 아웃을 위해 html을 렌더링하십시오. –

+0

감사합니다. 그게 해결책이야. 나는 로그 아웃이 완료된 컨트롤러를 무시하는 것과 비슷한 것을 찾고있었습니다. 하지만 그게 작동 할 것입니다 :) – ElPiter

+0

cool :) 사용하게되어 기쁘다! –

답변

4

당신은 CustomLogoutHandler 당신의 security.yml 구성에 추가 할 수 있습니다. your_bundle.custom_logout_handler이 담당 할 것

firewalls: 
    main: # - the name of your secure area 
     logout: 
      path: /logout 
      target:/
      success_handler: your_bundle.custom_logout_handler 

는 사용자를 로그 아웃하고, 예를 들어 비슷한 _target_url 매개 변수에 따라 그 리디렉션합니다.

는 세션 변수를 설정, 마음에 오는 Symfony/Component/Security/Http/Logout