Reputation: 5348
How can I redirect automaticaly an user when it enters a restricted page to /register-as-guest?
My wrong solution: in security.yml
I set
firewalls:
default:
form_login:
login_path: /register-as-guest
This works, but when user enters wrong credentials at login it is redirected to /register-as-guest
( login_path
) but should be redirected to /login
.
Upvotes: 0
Views: 91
Reputation: 4835
Just use the FOSUserBundle, everything you need is included there then you don't have to implement it on your own, also it is very well documented it is very is to integrate into a project
Upvotes: 0
Reputation: 856
You're on the right track :) Just a little more configuration is needed, as you can see in the docs If you want explicit behavior to happen on login success/failure, you should use these config settings under the firewall:
firewall:
default:
...
form_login:
...
# login success redirecting options
always_use_default_target_path: false
default_target_path: / # use this if you want a standard page to be shown on login success
target_path_parameter: _target_path
use_referer: false # set this to true to redirect back to the previously attempted page
# login failure redirecting options
failure_path: /foo
failure_forward: false # this is what you need
failure_path_parameter: _failure_path
failure_handler: some.service.id
success_handler: some.service.id
Hope this helps :)
Upvotes: 1