すでにログインしているユーザーをメイン ページにリダイレクトする方法はありますか? たとえば、Cookie を使用しているユーザーや「リメンバーミー」を使用しているユーザーなどは?
「loginController」でこれを試しましたが、機能しません
public function loginAction()
{
$request = $this->getRequest();
$session = $request->getSession();
// $user = new Usuario();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
}
$securityContext = $this->container->get('security.context');
if( $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') ){
$this->redirect($this->generateUrl('MonsePanelBundle_homepage'));
}
return $this->render('UsuariosBundle:Security:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
他の同様の質問をすべて読みましたが、これまでのところ運がありません...
念のため、これは私のsecurity.ymlです...
security:
encoders:
Monse\UsuariosBundle\Entity\Usuario:
algorithm: sha512
encode-as-base64: true
iterations: 10
role_hierarchy:
ROLE_ADMIN: [ROLE_USER]
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
user_db:
entity: { class: Monse\UsuariosBundle\Entity\Usuario, property: usuario }
firewalls:
main:
pattern: /.*
provider: user_db
form_login:
login_path: /login
check_path: /login_check
remember_me: true
default_target_path: /panel
logout:
path: /logout
target: /login
remember_me:
key: MiClaveSegura
lifetime: 1800
path: /.*
domain: ~
security: true
anonymous: true
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/panel, roles: [ROLE_SUPER_ADMIN, ROLE_ADMIN, ROLE_USER] }