1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Action\User; |
15
|
|
|
|
16
|
|
|
use Silverback\ApiComponentsBundle\Action\AbstractAction; |
17
|
|
|
use Silverback\ApiComponentsBundle\Factory\Response\ResponseFactory; |
18
|
|
|
use Silverback\ApiComponentsBundle\Manager\User\EmailAddressManager; |
19
|
|
|
use Silverback\ApiComponentsBundle\Serializer\SerializeFormatResolver; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
23
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
24
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @author Daniel West <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class EmailAddressVerifyAction extends AbstractAction |
30
|
|
|
{ |
31
|
|
|
private EmailAddressManager $emailAddressManager; |
32
|
|
|
|
33
|
|
|
public function __construct(SerializerInterface $serializer, SerializeFormatResolver $requestFormatResolver, ResponseFactory $responseFactory, EmailAddressManager $emailAddressManager) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($serializer, $requestFormatResolver, $responseFactory); |
36
|
|
|
$this->emailAddressManager = $emailAddressManager; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function __invoke(Request $request) |
40
|
|
|
{ |
41
|
|
|
$data = $this->serializer->decode($request->getContent(), $this->requestFormatResolver->getFormatFromRequest($request), []); |
42
|
|
|
$requiredKeys = ['username', 'email', 'token']; |
43
|
|
|
foreach ($requiredKeys as $requiredKey) { |
44
|
|
|
if (!isset($data[$requiredKey])) { |
45
|
|
|
throw new BadRequestHttpException(sprintf('the key `%s` was not found in POST data', $requiredKey)); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
$this->emailAddressManager->verifyNewEmailAddress($data['username'], $data['email'], $data['token']); |
51
|
|
|
|
52
|
|
|
return $this->responseFactory->create($request); |
53
|
|
|
} catch (NotFoundHttpException $exception) { |
54
|
|
|
return $this->responseFactory->create($request, $exception->getMessage(), Response::HTTP_NOT_FOUND); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|