2012-06-15 4 views
7

나는 로그 아웃 작업 후 플래시 메시지가 작동하는 방법을 알아 내기 위해 이미 몇 시간 만 노력하고 있습니다.심포니 로그 아웃 처리기

security.yml

login: 
     pattern: ^/login$ 
     security: false 

    secured_area: 
     pattern: ^/ 
     form_login: 
      check_path: /check 
      login_path: /login 
      failure_handler: authentication_handler 
     logout: 
      path: /logout 
      success_handler: authentication_handler 

config.yml

services: 
    authentication_handler: 
     class: Project\LoginBundle\Handler\AuthenticationHandler 

AuthenticationHandler.php

class AuthenticationHandler implements AuthenticationFailureHandlerInterface, LogoutSuccessHandlerInterface 
{ 
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception) 
    {  
     $referer = $request->headers->get('referer');  
     $request->getSession()->setFlash('error', $exception->getMessage()); 

     return new RedirectResponse($referer); 
    } 

    public function onLogoutSuccess(Request $request) 
    { 
     $referer = $request->headers->get('referer'); 
     $request->getSession()->setFlash('success', 'Wylogowano'); 


     return new RedirectResponse($referer); 
    } 
} 
V

iew 안녕하세요 로그인

{% extends "ProjectCMSBundle:Secured:layout.html.twig" %} 

{% block title "Hello " ~ name %} 

{% block content %} 
    <h1>Hello {{ name }}!</h1> 

    <a href="{{ path('_project_secured_hello_admin', { 'name': name }) }}">Hello resource secured for <strong>admin</strong> only.</a> 
{% endblock %} 

{% set code = code(_self) %} 

보기 로그인 양식

{% extends 'ProjectCMSBundle::layout.html.twig' %} 

{% block title %} 
    Title 
{% endblock %} 

{% block content %} 


    <form action="{{ path("_project_security_check") }}" method="post" id="login"> 
     <div class="data"> 
      <div class="username"> 
       <label for="username">&nbsp;</label> 
       <input type="text" id="username" name="_username" value="{{ last_username }}" /> 
      </div> 

      <div class="password"> 
       <label for="password">&nbsp;</label> 
       <input type="password" id="password" name="_password" /> 
      </div> 
     </div> 
    {% if error %} 
     <div class="error">{{ error.message|trans({},'messages') }}</div> 
    {% endif %} 
    <input type="submit" class="submit" /> 
</form> 
{% endblock %} 

{% set code = code(_self) %} 

레이아웃 기본 템플릿

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" href="{{ asset('bundles/project/css/demo.css') }}" type="text/css" media="all" /> 
    <title>{% block title %}{% endblock %}</title> 
    <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" /> 
</head> 
<body> 
    <div id="symfony-wrapper"> 

     {% if app.session.flash('error') %} 
      <div class="flash-message"> 
       {{ app.session.flash('error')|trans }} 
      </div> 
     {% endif %} 

     {% if app.session.flash('success') %} 
      <div class="flash-message"> 
       {{ app.session.flash('success')}} 
      </div> 
     {% endif %} 

     {% if app.user %} 
      {% block content_header %} 
      <ul id="menu"> 
       {% block content_header_more %} 
       {% endblock %} 
      </ul> 

      <div style="clear: both"></div> 
      {% endblock %} 
     {% endif %} 

     <div class="symfony-content"> 
      {% block content %} 
      {% endblock %} 
     </div> 

     {#{% if code is defined %} 
      <h2>Code behind this page</h2> 
      <div class="symfony-content">{{ code|raw }}</div> 
     {% endif %}#} 
    </div> 
</body> 

이후의 문제는 그 플래시 메시지가 리디렉션 동안 떨어지고 보인다는 것이다. 이것을 수행 할 방법이 있습니까?

답변 해 주셔서 감사합니다.

+0

보기를 표시 할 수 있습니까? ** invalidate_session **을 사용하는 경우 – sensorario

답변

19

로그 아웃시 세션이 파괴되었습니다. 하지만 security.yml 파일에 invalidate_session: false을 추가하여이 동작을 변경할 수 있습니다.

logout: 
    path: /logout 
    success_handler: authentication_handler 
    invalidate_session: false 

자세한 내용은 reference documentation을 확인하십시오.

여전히 세션을 무효화하려면 요청에 플래그를 직접 설정하고 커널 수신기와 함께 사용할 수 있습니다.

+1

** Flash가 나타나지만 RedirectResponse가 발생하지 않았습니다. – cavvako

+0

symfony 2.1 버전을 고려해 볼 것을 제안합니다. 플래시 메시지와 다른 호환 기능을 개선했습니다. –