我已经设置了一个角色:{ path: ^/, role: ROLE_USER }
,如果没有通过/login
验证,它会重定向。如何更改此重定向网址?
在我的security.yaml下面:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main_login:
pattern: ^/(fr|en|zh)/login$
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
check_path: fos_user_security_check
default_target_path: iot6_HomeBundle
logout:
path: fos_user_security_logout
target: fos_user_security_login
anonymous: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
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 }
- { path: ^/, role: ROLE_USER }
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
如果我正确理解您的问题,您需要覆盖FOSUserBundle的路线。像那样:
#config/routes/fos_user.yaml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
# ...
fos_user_security_login:
path: /yourRoute/login
defaults: { _controller: FOSUserBundle:Security:login, _method: POST }