Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PasswordReminderTokenMiddleware
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 handleBefore
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 handleAfter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Middleware;
6
7use PeServer\App\Models\AppConfiguration;
8use PeServer\App\Models\AppDatabase;
9use PeServer\App\Models\Dao\Entities\SignUpWaitEmailsEntityDao;
10use PeServer\Core\Database\IDatabaseConnection;
11use PeServer\Core\Http\HttpRequest;
12use PeServer\Core\Http\HttpRequestExists;
13use PeServer\Core\Http\HttpResponse;
14use PeServer\Core\Http\HttpStatus;
15use PeServer\Core\Mvc\Middleware\IMiddleware;
16use PeServer\Core\Mvc\Middleware\MiddlewareArgument;
17use PeServer\Core\Mvc\Middleware\MiddlewareResult;
18
19final 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}