Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

Commit ff288d3

Browse files
author
Ruben Schmidmeister
committed
Merge branch 'feature/password-reset'
2 parents 3252322 + b90865f commit ff288d3

File tree

96 files changed

+1893
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1893
-65
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2016 Ruben Schmidmeister <[email protected]>
4+
*
5+
* This program is free software. It comes without any warranty, to
6+
* the extent permitted by applicable law. You can redistribute it
7+
* and/or modify it under the terms of the GNU Affero General Public License,
8+
* version 3, as published by the Free Software Foundation.
9+
*/
10+
namespace Timetabio\API\Commands\User
11+
{
12+
use Timetabio\API\Services\UserService;
13+
use Timetabio\API\ValueObjects\Password;
14+
15+
class UpdateUserPasswordCommand
16+
{
17+
/**
18+
* @var UserService
19+
*/
20+
private $userService;
21+
22+
public function __construct(UserService $userService)
23+
{
24+
$this->userService = $userService;
25+
}
26+
27+
public function execute(string $userId, Password $password): void
28+
{
29+
$this->userService->updateUserPassword($userId, $password);
30+
}
31+
}
32+
}

API/src/DataStore/DataStoreReader.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public function getAccessToken(string $token): AccessToken
2424
return unserialize($this->getDataStore()->get('access_token_' . $token));
2525
}
2626

27+
public function hasResetToken(string $token): bool
28+
{
29+
return $this->getDataStore()->has('reset_token:' . $token);
30+
}
31+
32+
public function getResetToken(string $token): string
33+
{
34+
return $this->getDataStore()->get('reset_token:' . $token);
35+
}
36+
2737
/**
2838
* @deprecated
2939
*/

API/src/DataStore/DataStoreWriter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Timetabio\API\DataStore
1111
{
1212
use Timetabio\API\ValueObjects\AccessToken;
13+
use Timetabio\Framework\ValueObjects\Token;
1314
use Timetabio\Library\DataStore\AbstractDataStoreWriter;
1415

1516
class DataStoreWriter extends AbstractDataStoreWriter
@@ -36,6 +37,19 @@ public function removeAccessToken(AccessToken $token)
3637
$this->getDataStore()->remove('access_token_' . $token->getToken());
3738
}
3839

40+
public function saveResetToken(string $userId, Token $token)
41+
{
42+
$key = 'reset_token:' . $token;
43+
44+
$this->getDataStore()->set($key, $userId);
45+
$this->getDataStore()->setTimeout($key, 7200);
46+
}
47+
48+
public function removeResetToken(string $token)
49+
{
50+
$this->getDataStore()->remove('reset_token:' . $token);
51+
}
52+
3953
/**
4054
* @deprecated
4155
*/

API/src/Endpoints/AbstractEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function validate(Uri $uri): bool
4646
return $this->getEndpoint() === $uri->getPath();
4747
}
4848

49-
$explodedPath = $uri->getExplodedPath();
49+
$explodedPath = $uri->getPathSegments();
5050
$explodedEndpointPath = explode('/', ltrim($this->getEndpoint(), '/'));
5151

5252
if (count($explodedPath) !== count($explodedEndpointPath)) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2016 Manuel Lopez <[email protected]>
4+
*
5+
* This program is free software. It comes without any warranty, to
6+
* the extent permitted by applicable law. You can redistribute it
7+
* and/or modify it under the terms of the GNU Affero General Public License,
8+
* version 3, as published by the Free Software Foundation.
9+
*/
10+
namespace Timetabio\API\Endpoints
11+
{
12+
use Timetabio\API\Access\AccessTypes\AccessTypeInterface;
13+
use Timetabio\API\Access\AccessTypes\SystemAccess;
14+
use Timetabio\Framework\Controllers\ControllerInterface;
15+
use Timetabio\Framework\Http\Request\RequestInterface;
16+
17+
class ForgotPasswordEndpoint extends AbstractEndpoint
18+
{
19+
public function getEndpoint(): string
20+
{
21+
return '/v1/forgot';
22+
}
23+
24+
public function getRequestType(): string
25+
{
26+
return \Timetabio\Framework\Http\Request\PostRequest::class;
27+
}
28+
29+
public function hasAccess(AccessTypeInterface $accessType): bool
30+
{
31+
if ($accessType instanceof SystemAccess) {
32+
return true;
33+
}
34+
35+
return false;
36+
}
37+
38+
protected function doHandle(RequestInterface $request): ControllerInterface
39+
{
40+
return $this->getFactory()->createForgotPasswordController();
41+
}
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2016 Manuel Lopez <[email protected]>
4+
*
5+
* This program is free software. It comes without any warranty, to
6+
* the extent permitted by applicable law. You can redistribute it
7+
* and/or modify it under the terms of the GNU Affero General Public License,
8+
* version 3, as published by the Free Software Foundation.
9+
*/
10+
namespace Timetabio\API\Endpoints
11+
{
12+
use Timetabio\API\Access\AccessTypes\AccessTypeInterface;
13+
use Timetabio\API\Access\AccessTypes\SystemAccess;
14+
use Timetabio\Framework\Controllers\ControllerInterface;
15+
use Timetabio\Framework\Http\Request\RequestInterface;
16+
17+
class ResetPasswordEndpoint extends AbstractEndpoint
18+
{
19+
public function getEndpoint(): string
20+
{
21+
return '/v1/reset';
22+
}
23+
24+
public function getRequestType(): string
25+
{
26+
return \Timetabio\Framework\Http\Request\PostRequest::class;
27+
}
28+
29+
public function hasAccess(AccessTypeInterface $accessType): bool
30+
{
31+
if ($accessType instanceof SystemAccess) {
32+
return true;
33+
}
34+
35+
return false;
36+
}
37+
38+
protected function doHandle(RequestInterface $request): ControllerInterface
39+
{
40+
return $this->getFactory()->createResetPasswordController();
41+
}
42+
}
43+
}

API/src/Factories/CommandFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ public function createUpdateFeedUserCommand(): \Timetabio\API\Commands\Feed\Upda
202202
);
203203
}
204204

205+
public function createUpdateUserPasswordCommand(): \Timetabio\API\Commands\User\UpdateUserPasswordCommand
206+
{
207+
return new \Timetabio\API\Commands\User\UpdateUserPasswordCommand(
208+
$this->getMasterFactory()->createUserService()
209+
);
210+
}
211+
205212
public function createArchivePostCommand(): \Timetabio\API\Commands\Posts\ArchivePostCommand
206213
{
207214
return new \Timetabio\API\Commands\Posts\ArchivePostCommand(

API/src/Factories/ControllerFactory.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,36 @@ public function createUpdateUserPasswordController(): PutController
172172
);
173173
}
174174

175+
public function createResetPasswordController(): PostController
176+
{
177+
return new PostController(
178+
new \Timetabio\API\Models\ResetPasswordModel,
179+
$this->getMasterFactory()->createPreHandler(),
180+
$this->getMasterFactory()->createResetPasswordRequestHandler(),
181+
$this->getMasterFactory()->createResetPasswordQueryHandler(),
182+
$this->getMasterFactory()->createResetPasswordCommandHandler(),
183+
$this->getMasterFactory()->createTransformationHandler(),
184+
$this->getMasterFactory()->createResponseHandler(),
185+
$this->getMasterFactory()->createPostHandler(),
186+
new JsonResponse
187+
);
188+
}
189+
190+
public function createForgotPasswordController(): PostController
191+
{
192+
return new PostController(
193+
new \Timetabio\API\Models\ForgotPasswordModel,
194+
$this->getMasterFactory()->createPreHandler(),
195+
$this->getMasterFactory()->createForgotPasswordRequestHandler(),
196+
$this->getMasterFactory()->createForgotPasswordQueryHandler(),
197+
$this->getMasterFactory()->createForgotPasswordCommandHandler(),
198+
$this->getMasterFactory()->createTransformationHandler(),
199+
$this->getMasterFactory()->createResponseHandler(),
200+
$this->getMasterFactory()->createPostHandler(),
201+
new JsonResponse
202+
);
203+
}
204+
175205
public function createAuthController(): PostController
176206
{
177207
return new PostController(

API/src/Factories/EndpointFactory.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ public function createUpdateUserPasswordEndpoint(): \Timetabio\API\Endpoints\Use
6262
);
6363
}
6464

65+
public function createResetPasswordEndpoint(): \Timetabio\API\Endpoints\ResetPasswordEndpoint
66+
{
67+
return new \Timetabio\API\Endpoints\ResetPasswordEndpoint(
68+
$this->getMasterFactory()
69+
);
70+
}
71+
72+
public function createForgotPasswordEndpoint(): \Timetabio\API\Endpoints\ForgotPasswordEndpoint
73+
{
74+
return new \Timetabio\API\Endpoints\ForgotPasswordEndpoint(
75+
$this->getMasterFactory()
76+
);
77+
}
78+
6579
public function createGetProfileEndpoint(): \Timetabio\API\Endpoints\Profiles\GetProfileEndpoint
6680
{
6781
return new \Timetabio\API\Endpoints\Profiles\GetProfileEndpoint(

API/src/Factories/HandlerFactory.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,45 @@ public function createUpdateUserCommandHandler(): \Timetabio\API\Handlers\Patch\
153153
);
154154
}
155155

156+
public function createResetPasswordRequestHandler(): \Timetabio\API\Handlers\Post\Reset\RequestHandler
157+
{
158+
return new \Timetabio\API\Handlers\Post\Reset\RequestHandler;
159+
}
160+
161+
public function createResetPasswordQueryHandler(): \Timetabio\API\Handlers\Post\Reset\QueryHandler
162+
{
163+
return new \Timetabio\API\Handlers\Post\Reset\QueryHandler(
164+
$this->getMasterFactory()->createDataStoreReader()
165+
);
166+
}
167+
168+
public function createResetPasswordCommandHandler(): \Timetabio\API\Handlers\Post\Reset\CommandHandler
169+
{
170+
return new \Timetabio\API\Handlers\Post\Reset\CommandHandler(
171+
$this->getMasterFactory()->createUpdateUserPasswordCommand(),
172+
$this->getMasterFactory()->createDataStoreWriter()
173+
);
174+
}
175+
176+
public function createForgotPasswordRequestHandler(): \Timetabio\API\Handlers\Post\Forgot\RequestHandler
177+
{
178+
return new \Timetabio\API\Handlers\Post\Forgot\RequestHandler;
179+
}
180+
181+
public function createForgotPasswordQueryHandler(): \Timetabio\API\Handlers\Post\Forgot\QueryHandler
182+
{
183+
return new \Timetabio\API\Handlers\Post\Forgot\QueryHandler(
184+
$this->getMasterFactory()->createFetchAuthUserQuery()
185+
);
186+
}
187+
188+
public function createForgotPasswordCommandHandler(): \Timetabio\API\Handlers\Post\Forgot\CommandHandler
189+
{
190+
return new \Timetabio\API\Handlers\Post\Forgot\CommandHandler(
191+
$this->getMasterFactory()->createDataStoreWriter()
192+
);
193+
}
194+
156195
public function createUpdateUserPasswordQueryHandler(): \Timetabio\API\Handlers\Put\User\QueryHandler
157196
{
158197
return new \Timetabio\API\Handlers\Put\User\QueryHandler(
@@ -163,7 +202,7 @@ public function createUpdateUserPasswordQueryHandler(): \Timetabio\API\Handlers\
163202
public function createUpdateUserPasswordCommandHandler(): \Timetabio\API\Handlers\Put\User\CommandHandler
164203
{
165204
return new \Timetabio\API\Handlers\Put\User\CommandHandler(
166-
$this->getMasterFactory()->createUpdateUserCommand()
205+
$this->getMasterFactory()->createUpdateUserPasswordCommand()
167206
);
168207
}
169208

0 commit comments

Comments
 (0)