2014-02-05 36 views
0

我想知道如何在填写访问表单后登录时向用户显示不同的页面。我不得不在我的loginAction中这样做,但我不知道如何。symfony2 loginAction不同的渲染

我在loginAction如下:

public function loginAction() 
{ 
    $request = $this->getRequest(); 
    $session = $request->getSession(); 

    $error = $request->attributes->get(
     SecurityContext::AUTHENTICATION_ERROR, 
     $session->get(SecurityContext::AUTHENTICATION_ERROR) 
    ); 
    return $this->render('UsuarioBundle:Default:login.html.twig', array(
          'last_user' => $session->get(SecurityContext::LAST_USERNAME), 
          'error' => $error 
          )); 
} 

谢谢!

回答

0

尝试对检查security.context服务用户充分验证,如果是的话,渲染其他模板:

public function loginAction() 
{ 
    $request = $this->getRequest(); 
    $session = $request->getSession(); 

    $error = $request->attributes->get(
     SecurityContext::AUTHENTICATION_ERROR, 
     $session->get(SecurityContext::AUTHENTICATION_ERROR) 
    ); 

    if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') === TRUE) { 
     return $this->render('UsuarioBundle:Default:logined.html.twig'); // render other template for fully authenticated users 
    } 

    return $this->render('UsuarioBundle:Default:login.html.twig', array(
          'last_user' => $session->get(SecurityContext::LAST_USERNAME), 
          'error' => $error 
          )); 
}