Passed
Push — v2 ( 9b853e...868892 )
by Daniel
04:58
created

PasswordUpdateAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 22 3
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component 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\ApiComponentBundle\Action\User;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Security\Core\Exception\AuthenticationException;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class PasswordUpdateAction extends AbstractPasswordAction
24
{
25
    public function __invoke(Request $request)
26
    {
27
        $data = $this->serializer->decode($request->getContent(), $this->getFormat($request), []);
28
29
        $username = $data['username'];
30
        $token = $data['token'];
31
        $user = $this->userRepository->findOneByPasswordResetToken(
32
            $username,
33
            $token
34
        );
35
        if (!$user) {
36
            return $this->getResponse($request, null, Response::HTTP_NOT_FOUND);
37
        }
38
39
        try {
40
            $this->passwordManager->passwordReset($user, $data['password']);
41
42
            return $this->getResponse($request);
43
        } catch (AuthenticationException $exception) {
44
            $errors = $exception->getMessageData();
45
46
            return $this->getResponse($request, $errors, Response::HTTP_BAD_REQUEST);
47
        }
48
    }
49
}
50