Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PasswordReminderTokenMiddleware | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
handleAfter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Middleware; |
6 | |
7 | use PeServer\App\Models\AppConfiguration; |
8 | use PeServer\App\Models\AppDatabase; |
9 | use PeServer\App\Models\Dao\Entities\SignUpWaitEmailsEntityDao; |
10 | use PeServer\Core\Database\IDatabaseConnection; |
11 | use PeServer\Core\Http\HttpRequest; |
12 | use PeServer\Core\Http\HttpRequestExists; |
13 | use PeServer\Core\Http\HttpResponse; |
14 | use PeServer\Core\Http\HttpStatus; |
15 | use PeServer\Core\Mvc\Middleware\IMiddleware; |
16 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
17 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
18 | |
19 | final class PasswordReminderTokenMiddleware implements IMiddleware |
20 | { |
21 | public function __construct( |
22 | private AppConfiguration $config, |
23 | private IDatabaseConnection $connection |
24 | ) { |
25 | } |
26 | |
27 | //[IMiddleware] |
28 | |
29 | public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
30 | { |
31 | $tokenState = $argument->request->exists('token'); |
32 | if ($tokenState->exists && $tokenState->kind === HttpRequestExists::KIND_URL) { |
33 | $token = $argument->request->getValue($tokenState->name); |
34 | |
35 | $database = $this->connection->open(); |
36 | $signUpWaitEmailsEntityDao = new SignUpWaitEmailsEntityDao($database); |
37 | |
38 | $limitMinutes = $this->config->setting->config->confirm->signUpWaitEmailMinutes; |
39 | if ($signUpWaitEmailsEntityDao->selectExistsToken($token, $limitMinutes)) { |
40 | return MiddlewareResult::none(); |
41 | } |
42 | } |
43 | |
44 | return MiddlewareResult::error(HttpStatus::NotFound); |
45 | } |
46 | |
47 | public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
48 | { |
49 | return MiddlewareResult::none(); |
50 | } |
51 | } |