@@ 23-94 (lines=72) @@ | ||
20 | * @link https://dev.commercetools.com/http-api-projects-customers.html#reset-customers-password |
|
21 | * @method Customer mapResponse(ApiResponseInterface $response) |
|
22 | */ |
|
23 | class CustomerPasswordResetRequest extends AbstractApiRequest |
|
24 | { |
|
25 | const TOKEN_VALUE = 'tokenValue'; |
|
26 | const NEW_PASSWORD = 'newPassword'; |
|
27 | ||
28 | protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
|
29 | ||
30 | /** |
|
31 | * @var string |
|
32 | */ |
|
33 | protected $tokenValue; |
|
34 | ||
35 | /** |
|
36 | * @var string |
|
37 | */ |
|
38 | protected $newPassword; |
|
39 | ||
40 | /** |
|
41 | * @param string $id |
|
42 | * @param int $version |
|
43 | * @param string $tokenValue |
|
44 | * @param string $newPassword |
|
45 | * @param Context $context |
|
46 | */ |
|
47 | public function __construct($tokenValue, $newPassword, Context $context = null) |
|
48 | { |
|
49 | parent::__construct(CustomersEndpoint::endpoint(), $context); |
|
50 | $this->tokenValue = $tokenValue; |
|
51 | $this->newPassword = $newPassword; |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * @param string $tokenValue |
|
56 | * @param string $newPassword |
|
57 | * @param Context $context |
|
58 | * @return static |
|
59 | */ |
|
60 | public static function ofTokenAndPassword( |
|
61 | $tokenValue, |
|
62 | $newPassword, |
|
63 | Context $context = null |
|
64 | ) { |
|
65 | return new static($tokenValue, $newPassword, $context); |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @return string |
|
70 | * @internal |
|
71 | */ |
|
72 | protected function getPath() |
|
73 | { |
|
74 | return (string)$this->getEndpoint() . '/password/reset' . $this->getParamString(); |
|
75 | } |
|
76 | ||
77 | /** |
|
78 | * @return JsonRequest |
|
79 | * @internal |
|
80 | */ |
|
81 | public function httpRequest() |
|
82 | { |
|
83 | $payload = [ |
|
84 | static::TOKEN_VALUE => $this->tokenValue, |
|
85 | static::NEW_PASSWORD => $this->newPassword |
|
86 | ]; |
|
87 | return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
|
88 | } |
|
89 | ||
90 | public function buildResponse(ResponseInterface $response) |
|
91 | { |
|
92 | return new ResourceResponse($response, $this, $this->getContext()); |
|
93 | } |
|
94 | } |
|
95 |
@@ 21-95 (lines=75) @@ | ||
18 | * @package Commercetools\Core\Request\Me |
|
19 | * @method Customer mapResponse(ApiResponseInterface $response) |
|
20 | */ |
|
21 | class MePasswordResetRequest extends AbstractApiRequest |
|
22 | { |
|
23 | const TOKEN_VALUE = 'tokenValue'; |
|
24 | const NEW_PASSWORD = 'newPassword'; |
|
25 | ||
26 | protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
|
27 | ||
28 | /** |
|
29 | * @var string |
|
30 | */ |
|
31 | protected $token; |
|
32 | ||
33 | /** |
|
34 | * @var string |
|
35 | */ |
|
36 | protected $newPassword; |
|
37 | ||
38 | /** |
|
39 | * @param string $token |
|
40 | * @param string $newPassword |
|
41 | * @param Context $context |
|
42 | */ |
|
43 | public function __construct($token, $newPassword, Context $context = null) |
|
44 | { |
|
45 | parent::__construct(MeEndpoint::endpoint(), $context); |
|
46 | $this->token = $token; |
|
47 | $this->newPassword = $newPassword; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * @param string $token |
|
52 | * @param string $newPassword |
|
53 | * @param Context $context |
|
54 | * @return static |
|
55 | */ |
|
56 | public static function ofTokenAndPassword( |
|
57 | $token, |
|
58 | $newPassword, |
|
59 | Context $context = null |
|
60 | ) { |
|
61 | return new static($token, $newPassword, $context); |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * @return string |
|
66 | * @internal |
|
67 | */ |
|
68 | protected function getPath() |
|
69 | { |
|
70 | return (string)$this->getEndpoint() . '/password/reset' . $this->getParamString(); |
|
71 | } |
|
72 | ||
73 | /** |
|
74 | * @return JsonRequest |
|
75 | * @internal |
|
76 | */ |
|
77 | public function httpRequest() |
|
78 | { |
|
79 | $payload = [ |
|
80 | static::TOKEN_VALUE => $this->token, |
|
81 | static::NEW_PASSWORD => $this->newPassword |
|
82 | ]; |
|
83 | return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * @param ResponseInterface $response |
|
88 | * @return ResourceResponse |
|
89 | * @internal |
|
90 | */ |
|
91 | public function buildResponse(ResponseInterface $response) |
|
92 | { |
|
93 | return new ResourceResponse($response, $this, $this->getContext()); |
|
94 | } |
|
95 | } |
|
96 |