Skip to content

Instantly share code, notes, and snippets.

@wpottier
Created September 6, 2012 12:45
Show Gist options
  • Save wpottier/3655881 to your computer and use it in GitHub Desktop.
Save wpottier/3655881 to your computer and use it in GitHub Desktop.
/**
* @Route("/security/login",)
* @Template()
*/
public function loginAction() {
if ($this->get("security.context")->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirect($this->generateUrl('mon_site_blog_default_index'));
}
$request = $this->getRequest();
$session = $request->getSession();
// 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);
}
if (!empty ($error)) {
$session->getFlashBag()->set('error', $error->getMessage());
}
return array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment