FOS\UserBundle\Controller\SecurityController::loginAction PHP Method

loginAction() public method

public loginAction ( )
    public function loginAction()
    {
        // get the error if any (works with forward and redirect -- see below)
        if ($this->container->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $this->container->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $this->container->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
            $this->container->get('request')->getSession()->remove(SecurityContext::AUTHENTICATION_ERROR);
        }
        if ($error) {
            // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523)
            $error = $error->getMessage();
        }
        return $this->container->get('templating')->renderResponse('FOSUserBundle:Security:login.html.' . $this->getEngine(), array('last_username' => $this->container->get('request')->getSession()->get(SecurityContext::LAST_USERNAME), 'error' => $error));
    }

Usage Example

 /**
  * redirect to home when already authenticated
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function loginAction(Request $request)
 {
     if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         return $this->redirectToRoute('campaignchain_core_homepage');
     }
     return parent::loginAction($request);
 }
All Usage Examples Of FOS\UserBundle\Controller\SecurityController::loginAction