|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoS\UserBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use DoS\UserBundle\Confirmation\ConfirmationInterface; |
|
6
|
|
|
use DoS\UserBundle\Model\UserInterface; |
|
7
|
|
|
use FOS\RestBundle\View\View; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
11
|
|
|
|
|
12
|
|
|
class ConfirmationController extends SyliusUserController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param $key |
|
16
|
|
|
* @param array $parameters |
|
17
|
|
|
* @param null $domain |
|
18
|
|
|
* |
|
19
|
|
|
* @return string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function trans($key, $parameters = array(), $domain = null) |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->get('translator')->trans($key, $parameters, $domain); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param Request $request |
|
28
|
|
|
* |
|
29
|
|
|
* @return RedirectResponse |
|
30
|
|
|
*/ |
|
31
|
|
|
public function confirmationResendAction(Request $request) |
|
32
|
|
|
{ |
|
33
|
|
|
$confirmation = $this->getConfirmationService(); |
|
34
|
|
|
$form = $confirmation->resend($request); |
|
35
|
|
|
$config = $this->requestConfigurationFactory->create($this->metadata, $request); |
|
36
|
|
|
|
|
37
|
|
|
$view = View::create(array( |
|
38
|
|
|
'type' => $confirmation->getType(), |
|
39
|
|
|
'form' => $form->createView() |
|
40
|
|
|
))->setTemplate($config->getTemplate('resend')); |
|
41
|
|
|
|
|
42
|
|
|
return $this->viewHandler->handle($config, $view); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param Request $request |
|
47
|
|
|
* |
|
48
|
|
|
* @return Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function confirmationAction(Request $request) |
|
51
|
|
|
{ |
|
52
|
|
|
$confirmation = $this->getConfirmationService(); |
|
53
|
|
|
$token = $confirmation->getStoredToken(true); |
|
54
|
|
|
$subject = $confirmation->findSubjectWithToken($token); |
|
55
|
|
|
$config = $this->requestConfigurationFactory->create($this->metadata, $request); |
|
56
|
|
|
|
|
57
|
|
|
$view = View::create(array( |
|
58
|
|
|
'type' => $confirmation->getType(), |
|
59
|
|
|
'subject' => $subject, |
|
60
|
|
|
'subjectValue' => $confirmation->getSubjectValue($subject), |
|
61
|
|
|
'time_aware' => $confirmation->getTokenTimeAware($subject), |
|
62
|
|
|
'resendForm' => $confirmation->createResendForm()->createView(), |
|
63
|
|
|
'verifyForm' => $confirmation->createVerifyForm()->createView(), |
|
64
|
|
|
))->setTemplate($config->getTemplate('confirmation')); |
|
65
|
|
|
|
|
66
|
|
|
return $this->viewHandler->handle($config, $view); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param Request $request |
|
71
|
|
|
* @param string $token |
|
72
|
|
|
* |
|
73
|
|
|
* @return Response |
|
74
|
|
|
*/ |
|
75
|
|
|
public function verificationAction(Request $request, $token) |
|
76
|
|
|
{ |
|
77
|
|
|
$confirmation = $this->getConfirmationService(); |
|
78
|
|
|
$form = $confirmation->verify($request, $token); |
|
79
|
|
|
$config = $this->requestConfigurationFactory->create($this->metadata, $request); |
|
80
|
|
|
|
|
81
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
82
|
|
|
/** @var UserInterface $user */ |
|
83
|
|
|
$user = $form->getData()->getSubject(); |
|
84
|
|
|
$this->get('sylius.security.user_login')->login($user); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$view = View::create(array( |
|
88
|
|
|
'type' => $confirmation->getType(), |
|
89
|
|
|
'form' => $form->createView() |
|
90
|
|
|
))->setTemplate($config->getTemplate('verification')); |
|
91
|
|
|
|
|
92
|
|
|
return $this->viewHandler->handle($config, $view); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return ConfirmationInterface|null |
|
97
|
|
|
* |
|
98
|
|
|
* @throws \Exception |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getConfirmationService() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->get('dos.user.confirmation.factory')->createActivedConfirmation(true); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|