@@ 64-81 (lines=18) @@ | ||
61 | * |
|
62 | * @return ResponseInterface |
|
63 | */ |
|
64 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
|
65 | { |
|
66 | if (!Middleware::hasAttribute($request, FormatNegotiator::KEY)) { |
|
67 | throw new RuntimeException('Honeypot middleware needs FormatNegotiator executed before'); |
|
68 | } |
|
69 | ||
70 | if (FormatNegotiator::getFormat($request) !== 'html') { |
|
71 | return $next($request, $response); |
|
72 | } |
|
73 | ||
74 | if ($this->isPost($request) && !$this->isValid($request)) { |
|
75 | return $response->withStatus(403); |
|
76 | } |
|
77 | ||
78 | $response = $next($request, $response); |
|
79 | ||
80 | return $this->insertIntoPostForms($response, '<input type="text" name="'.$this->inputName.'" class="'.$this->inputClass.'">'); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * Check whether the request is valid. |
@@ 86-103 (lines=18) @@ | ||
83 | * |
|
84 | * @return ResponseInterface |
|
85 | */ |
|
86 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
|
87 | { |
|
88 | if (!Middleware::hasAttribute($request, FormatNegotiator::KEY)) { |
|
89 | throw new RuntimeException('FormTimestamp middleware needs FormatNegotiator executed before'); |
|
90 | } |
|
91 | ||
92 | if (FormatNegotiator::getFormat($request) !== 'html') { |
|
93 | return $next($request, $response); |
|
94 | } |
|
95 | ||
96 | if ($this->isPost($request) && !$this->isValid($request)) { |
|
97 | return $response->withStatus(403); |
|
98 | } |
|
99 | ||
100 | $response = $next($request, $response); |
|
101 | ||
102 | return $this->insertIntoPostForms($response, '<input type="hidden" name="'.$this->inputName.'" value="'.$this->encrypt(time()).'">'); |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * Check whether the request is valid. |