登录后从登录页面重定向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)
OR
/login (front end user)
然后应将其重定向回相关的主页,例如/admin
或/
then they should be redirected back to their related home page like /admin
or /
推荐答案
You can override FOSUserBundle\Controller\SecurityController and add the following code at the top of loginAction
.
use Symfony\Component\HttpFoundation\RedirectResponse;
// ...
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屋!
查看全文