|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FlyingColours\TwilioTwoFactorBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use FlyingColours\TwilioTwoFactorBundle\Model\Twilio\TwoFactorInterface; |
|
6
|
|
|
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorToken; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
|
8
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
9
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
10
|
|
|
use Symfony\Component\Form\FormInterface; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
14
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
15
|
|
|
|
|
16
|
|
|
class TriggerController |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var RouterInterface */ |
|
19
|
|
|
private $router; |
|
20
|
|
|
|
|
21
|
|
|
/** @var EventDispatcherInterface */ |
|
22
|
|
|
private $dispatcher; |
|
23
|
|
|
|
|
24
|
|
|
/** @var EngineInterface */ |
|
25
|
|
|
private $templating; |
|
26
|
|
|
|
|
27
|
|
|
/** @var FormInterface */ |
|
28
|
|
|
private $form; |
|
29
|
|
|
|
|
30
|
|
|
/** @var TwoFactorToken */ |
|
31
|
|
|
private $token; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* TriggerController constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param RouterInterface $router |
|
37
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
38
|
|
|
* @param EngineInterface $templating |
|
39
|
|
|
* @param FormInterface $form |
|
40
|
|
|
* @param TwoFactorToken $token |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function __construct( |
|
43
|
|
|
RouterInterface $router, |
|
44
|
|
|
EventDispatcherInterface $dispatcher, |
|
45
|
|
|
EngineInterface $templating, |
|
46
|
|
|
FormInterface $form, |
|
47
|
|
|
TwoFactorToken $token |
|
48
|
|
|
) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$this->router = $router; |
|
51
|
2 |
|
$this->dispatcher = $dispatcher; |
|
52
|
2 |
|
$this->templating = $templating; |
|
53
|
2 |
|
$this->form = $form; |
|
54
|
2 |
|
$this->token = $token; |
|
55
|
2 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function defaultAction(Request $request) |
|
58
|
|
|
{ |
|
59
|
1 |
|
$this->form->setData($this->token->getUser()); |
|
60
|
|
|
|
|
61
|
1 |
|
$this->form->handleRequest($request); |
|
62
|
|
|
|
|
63
|
1 |
|
if ($this->form->isValid()) |
|
64
|
|
|
{ |
|
65
|
|
|
/** @var TwoFactorInterface $user */ |
|
66
|
1 |
|
$user = $this->form->getData(); |
|
67
|
|
|
|
|
68
|
|
|
/** @var GenericEvent $event */ |
|
69
|
1 |
|
$event = $this->dispatcher->dispatch('twilio.auth.triggered', new GenericEvent($user)); |
|
70
|
|
|
|
|
71
|
1 |
|
$route = $event->hasArgument('route') |
|
72
|
1 |
|
? $event->getArgument('route') |
|
73
|
1 |
|
: '2fa_login' |
|
74
|
|
|
; |
|
75
|
|
|
|
|
76
|
1 |
|
return new RedirectResponse($this->router->generate($route)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
return $this->templating->renderResponse( |
|
80
|
1 |
|
'@FlyingColoursTwilioTwoFactor/trigger/default.html.twig', |
|
81
|
1 |
|
[ 'form' => $this->form->createView() ] |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|