1

我已经设法让登录在 Symfony2 中工作,但是 /logout 有问题。我收到一个异常,说它找不到路由的控制器。但是,我的印象是 Symfony 处理注销过程,就像它处理登录一样?

(部分)我的 security.yml 文件:

firewalls:
    login_firewall:
        pattern:    ^/login/
        anonymous:  ~
    secured_area:
        pattern:    ^/(dashboard|directories|login_check)/
        anonymous: ~
        form_login:
            login_path:  /login/
            check_path:  /login_check/
        logout:
            path:   /logout/
            target: /

我的(相关)路线:

_login:
    pattern: /login/
    defaults: { _controller: NanoBundle:Login:index } 

_login_check:
    pattern: /login_check/

_logout:
    pattern: /logout/

--edit:注销按钮代码:

<a href="{{path('_logout')}}">Logout</a>
4

2 回答 2

0

我最终用这个 security.yml 部分修复了它:

    secured_area:
        pattern:    .*
        security: true
        form_login:
            login_path:  /login/
            check_path:  /login_check/
        logout:
            path: /logout/
            invalidate_session: true

感谢大家为此提供帮助:)

于 2012-08-25T17:56:47.667 回答
0

用这个 security.yml 部分修复它:

security:
    providers:
        fos_userbundle:
            id: fos_user.user_manager

encoders:
    FOS\UserBundle\Model\UserInterface: sha512

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/*, role: ROLE_ADMIN }
     # URL of FOSUserBundle which need to be available to anonymous users
    - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

试试这个可能对你有帮助..:)

于 2012-08-27T05:47:00.630 回答