|
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 Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
20
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Daniel West <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class PasswordUpdateAction extends AbstractPasswordAction |
|
26
|
|
|
{ |
|
27
|
|
|
public function __invoke(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$data = $this->serializer->decode($request->getContent(), $this->requestFormatResolver->getFormatFromRequest($request), []); |
|
30
|
|
|
$requiredKeys = ['username', 'token', 'password']; |
|
31
|
|
|
foreach ($requiredKeys as $requiredKey) { |
|
32
|
|
|
if (!isset($data[$requiredKey])) { |
|
33
|
|
|
throw new BadRequestHttpException(sprintf('the key `%s` was not found in POST data', $requiredKey)); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
$this->passwordManager->passwordReset($data['username'], $data['token'], $data['password']); |
|
39
|
|
|
|
|
40
|
|
|
return $this->responseFactory->create($request); |
|
41
|
|
|
} catch (AuthenticationException $exception) { |
|
42
|
|
|
$errors = $exception->getMessageData(); |
|
43
|
|
|
|
|
44
|
|
|
return $this->responseFactory->create($request, $errors, Response::HTTP_BAD_REQUEST); |
|
45
|
|
|
} catch (NotFoundHttpException $exception) { |
|
46
|
|
|
return $this->responseFactory->create($request, $exception->getMessage(), Response::HTTP_NOT_FOUND); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|