登录后从登录页面重定向 FOSUserBundle [英] FOSUserBundle redirect from login page after logged in
本文介绍了登录后从登录页面重定向 FOSUserBundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是希望如果管理员用户或前端用户即使在登录后也尝试访问登录页面
I simply want that if admin user or front end user try to access login page even after logged in
/admin/login (admin user)
或
/login (front end user)
然后他们应该被重定向回他们的相关主页,如 /admin
或 /
then they should be redirected back to their related home page like /admin
or /
推荐答案
您可以覆盖 FOSUserBundleControllerSecurityController 并在 loginAction
的顶部添加以下代码.
You can override FOSUserBundleControllerSecurityController and add the following code at the top of loginAction
.
use SymfonyComponentHttpFoundationRedirectResponse;
// ...
public function loginAction(Request $request)
{
$authChecker = $this->container->get('security.authorization_checker');
$router = $this->container->get('router');
if ($authChecker->isGranted('ROLE_ADMIN')) {
return new RedirectResponse($router->generate('admin_home'), 307);
}
if ($authChecker->isGranted('ROLE_USER')) {
return new RedirectResponse($router->generate('user_home'), 307);
}
// ...
这篇关于登录后从登录页面重定向 FOSUserBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文