Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

onAuthenticationSuccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\UserBundle\Authentication;
13
14
use Symfony\Component\HttpFoundation\JsonResponse;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
28
    {
29
        if ($request->isXmlHttpRequest()) {
30
            return new JsonResponse(['success' => true, 'username' => $token->getUsername()]);
31
        }
32
33
        return parent::onAuthenticationSuccess($request, $token);
34
    }
35
}
36