Skip to content

Instantly share code, notes, and snippets.

Created February 25, 2015 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c44ce797fc93fdb86fa2 to your computer and use it in GitHub Desktop.
Save anonymous/c44ce797fc93fdb86fa2 to your computer and use it in GitHub Desktop.
<?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