-
-
Save anonymous/c44ce797fc93fdb86fa2 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* This file is part of the Welcome project. | |
* | |
* (c) Chris BECKER <goabonga@gmail.com> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace AppBundle\Security\Http\Authentication; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Routing\RouterInterface; | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; | |
use Symfony\Component\Security\Http\HttpUtils; | |
class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler | |
{ | |
private $router; | |
public function __construct(RouterInterface $router, HttpUtils $httpUtils) | |
{ | |
$this->router = $router; | |
$this->httpUtils = $httpUtils; | |
parent::__construct($httpUtils, array()); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function onAuthenticationSuccess(Request $request, TokenInterface $token) | |
{ | |
if ($request->isXmlHttpRequest()) { | |
$array = array( | |
'success' => true, | |
'message' => sprintf('User %s is now authenticated', $token->getUsername()), | |
); | |
$response = new Response(json_encode($array)); | |
$response->headers->set('Content-Type', 'application/json'); | |
return $response; | |
} else { | |
return parent::onAuthenticationSuccess($request, $token); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment