|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Api\User; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
9
|
|
|
use Uxmp\Core\Api\AbstractApiApplication; |
|
10
|
|
|
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware; |
|
11
|
|
|
use Uxmp\Core\Api\Lib\SchemaValidatorInterface; |
|
12
|
|
|
use Uxmp\Core\Component\User\PasswordVerificatorInterface; |
|
13
|
|
|
use Uxmp\Core\Orm\Model\UserInterface; |
|
14
|
|
|
use Uxmp\Core\Orm\Repository\UserRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Sets the current user's password |
|
18
|
|
|
*/ |
|
19
|
|
|
final class UserSettingsPasswordUpdateApplication extends AbstractApiApplication |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param SchemaValidatorInterface<array{password: string}> $schemaValidator |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function __construct( |
|
25
|
|
|
private readonly UserRepositoryInterface $userRepository, |
|
26
|
|
|
private readonly PasswordVerificatorInterface $passwordVerificator, |
|
27
|
|
|
private readonly SchemaValidatorInterface $schemaValidator, |
|
28
|
|
|
) { |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
protected function run( |
|
32
|
|
|
ServerRequestInterface $request, |
|
33
|
|
|
ResponseInterface $response, |
|
34
|
|
|
array $args |
|
35
|
|
|
): ResponseInterface { |
|
36
|
1 |
|
$body = $this->schemaValidator->getValidatedBody( |
|
37
|
|
|
$request, |
|
38
|
|
|
'UserPasswordUpdate.json', |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
/** @var UserInterface $user */ |
|
42
|
1 |
|
$user = $request->getAttribute(SessionValidatorMiddleware::USER); |
|
43
|
|
|
|
|
44
|
1 |
|
$password = $body['password']; |
|
45
|
|
|
|
|
46
|
1 |
|
$user->setPassword( |
|
47
|
1 |
|
$this->passwordVerificator->hash($password) |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
1 |
|
$this->userRepository->save($user); |
|
51
|
|
|
|
|
52
|
1 |
|
return $response; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|