public function loginAction(Request $request)
{
$session = $request->getSession();
$templatesService = $this->get('newscoop.templates.service');
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = false;
}
if ($error) {
$error = $error->getMessage();
}
$lastUsername = null === $session ? '' : $session->get(SecurityContext::LAST_USERNAME);
$smarty = $templatesService->getSmarty();
$smarty->assign('lastUsername', $lastUsername);
$smarty->assign('error', $error);
$smarty->assign('targetPath', $request->getSession()->get('_security.oauth_authorize.target_path'));
return new Response($templatesService->fetchTemplate('oauth_login.tpl'), 200, array('Content-Type' => 'text/html'));
}