重定向到单击(引用)链接的URL [英] Redirect to the url of the clicked (referred) link
问题描述
我有一种情况,用户会从系统收到带有特定链接的电子邮件,该链接需要登录.比如说链接是http://test.url.com/product/2
.单击此链接的位置会将用户重定向到登录页面,并应在成功登录后重定向到收到的URL.
I have a scenario where the user receives an email from the system with a specific link which requires login. say for example the link is http://test.url.com/product/2
. Where clicking on this link redirects the user to the sign in page and should redirect to the received url upon success login.
但是我遇到的问题是系统始终将重定向到默认位置http://test.url.com/dashboard
.
But the issue I am having is the system always redirects to the default location which is http://test.url.com/dashboard
.
To implement this I used http://symfony.com/doc/current/reference/configuration/security.html#redirecting-after-login use_referer: true
in security.yml
and to test it I have used print_r($request->headers->get('referer'));
on the sign in page.
但是,当我单击电子邮件中的链接时,它始终返回null
,但是,当我注销系统并登陆登录页面时,它将返回正确的引荐来源网址.
But this always returns null
when I click the link from the email but, it returns the proper referrer url when I logout of the system and lands on the sign in page.
编辑-security.yml
security:
providers:
in_memory:
memory: ~
webservice:
id: user_provider
encoders:
Project\Bundle\LoginBundle\Security\User\User: plaintext
access_control:
- { path: ^/signin, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "^/(signup|forgotpassword|resetpassword/[0-9a-z]+)?$", roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
firewalls:
secured_area:
pattern: ^/
anonymous: ~
form_login:
login_path: /signin
check_path: _security_check
access_denied_url: forgotpassword
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
default:
anonymous: true
推荐答案
因此,您有2个选择:
您可以手动填充引用程序,也可以通过在security.yml中指定登录名来导致登录重定向,从而将其填充到控制器中.我建议使用security.yml方法,因为我实际上没有尝试过手动填充,因为我对此事不信任自己或任何其他人,因此始终记得在这种情况下填充引用. security.yml还有一个好处,就是没有到处都有重定向代码.
You can either populate the referer manually or you can have it populate in your controller by causing a login redirect by specifying it in your security.yml. i recommend the security.yml way as i haven't actually tried the manual population because i don't trust myself or anyone else for that matter to always remember to populate the refer in those situations. security.yml also has the benefit of not having redirect code all over the place.
$request->getSession()->set('referer', $request->attributes->all());
或
access_control:
- { path: ^/product/.*, roles: IS_AUTHENTICATED_REMEMBERED }
这篇关于重定向到单击(引用)链接的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!