Created
May 29, 2014 12:53
-
-
Save morontt/594e15c21ce73b4e7fd4 to your computer and use it in GitHub Desktop.
example LoginController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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