Skip to content

Instantly share code, notes, and snippets.

@morontt
Created May 29, 2014 12:53
Show Gist options
  • Save morontt/594e15c21ce73b4e7fd4 to your computer and use it in GitHub Desktop.
Save morontt/594e15c21ce73b4e7fd4 to your computer and use it in GitHub Desktop.
example LoginController
<?php
namespace Xxx\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class LoginController extends Controller
{
/**
* @Template()
*
* @param Request $request
* @return array
*/
public function loginAction(Request $request)
{
$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);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return [
'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