我只有安装了FOSUserBundle才能使用干净的Symfony 2.8.4 app。我用基本文档配置了它。我改变了路线,因为我需要翻译它们。
我改变了这些路线:
/ login => / prihlaseni
和
/ logout => / odhlasit
在route / prihlaseni我可以看到表单,但是当我发送错误的凭据时,我得到找不到“GET / login”的路由(来自http://localhost/project/web/app_dev.php/prihlaseni“)
我找不到任何理由,为什么它会再次重定向到/ login。为什么会这样呢?
我的routing.yml:
app:
resource: "@AppBundle/Controller/"
type: annotation
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profil
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /registrace
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /reset
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profil
fos_user_security_login:
path: /prihlaseni
defaults: { _controller: FOSUserBundle:Security:login, _method: POST }
fos_user_security_logout:
path: /odhlasit
defaults: { _controller: FOSUserBundle:Security:logout, _method: POST }
我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
anonymous: true
logout:
path: /odhlasit
target: /
access_control:
- { path: ^/prihlaseni$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/registrace, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/reset, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
注册,使用正确的凭据登录并注销工作正常。