Completed
Push — master ( e79dfa...ffecda )
by Benjamin
02:16
created

AuthenticationHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\UserBundle\Handler;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
8
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
9
use Symfony\Bundle\FrameworkBundle\Routing\Router;
10
11
class AuthenticationHandler implements AuthenticationSuccessHandlerInterface
12
{
13
    protected $router;
14
15
    public function __construct(Router $router)
16
    {
17
        $this->router = $router;
18
    }
19
20
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
21
    {
22
        $back = $request->get('back');
23
24
        if (!empty($back) && $back != "/404") {
25
            return new RedirectResponse($back);
26
        }
27
28
        return new RedirectResponse($this->router->generate('front_home'));
29
    }
30
}
31