|
1 | | -<?php namespace App\Filters; |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filters; |
2 | 4 |
|
3 | 5 | use CodeIgniter\Filters\FilterInterface; |
4 | 6 | use CodeIgniter\HTTP\RequestInterface; |
5 | 7 | use CodeIgniter\HTTP\ResponseInterface; |
6 | 8 | use Config\Services; |
7 | 9 | use CodeIgniter\Honeypot\Exceptions\HoneypotException; |
| 10 | +use CodeIgniter\Honeypot\Honeypot; |
8 | 11 |
|
9 | | -class Honeypot implements FilterInterface |
| 12 | +class Honeypot implements FilterInterface |
10 | 13 | { |
11 | 14 |
|
12 | | - /** |
13 | | - * Checks if Honeypot field is empty, if so |
14 | | - * then the requester is a bot,show a blank |
15 | | - * page |
| 15 | + /** |
| 16 | + * Checks if Honeypot field is empty; if not |
| 17 | + * then the requester is a bot |
16 | 18 | * |
17 | | - * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request |
| 19 | + * @param CodeIgniter\HTTP\RequestInterface $request |
18 | 20 | * |
19 | 21 | * @return mixed |
20 | 22 | */ |
| 23 | + public function before(RequestInterface $request) |
| 24 | + { |
| 25 | + $honeypot = new Honeypot(new \Config\Honeypot()); |
| 26 | + if ($honeypot->hasContent($request)) |
| 27 | + { |
| 28 | + throw HoneypotException::isBot(); |
| 29 | + } |
| 30 | + } |
21 | 31 |
|
22 | | - public function before (RequestInterface $request) |
23 | | - { |
24 | | - |
25 | | - // Checks honeypot field if value was entered then show blank if so. |
26 | | - |
27 | | - $honeypot = Services::honeypot(new \Config\Honeypot()); |
28 | | - if($honeypot->hasContent($request)) |
29 | | - { |
30 | | - throw HoneypotException::isBot(); |
31 | | - } |
32 | | - |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Checks if Honeypot field is empty, if so |
37 | | - * then the requester is a bot,show a blank |
38 | | - * page |
| 32 | + /** |
| 33 | + * Attach a honypot to the current response. |
39 | 34 | * |
40 | | - * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request |
41 | | - * @param ResponseInterface|\CodeIgniter\HTTP\Response $response |
| 35 | + * @param CodeIgniter\HTTP\RequestInterface $request |
| 36 | + * @param CodeIgniter\HTTP\ResponseInterface $response |
42 | 37 | * @return mixed |
43 | 38 | */ |
| 39 | + public function after(RequestInterface $request, ResponseInterface $response) |
| 40 | + { |
| 41 | + $honeypot = new Honeypot(new \Config\Honeypot()); |
| 42 | + $honeypot->attachHoneypot($response); |
| 43 | + } |
44 | 44 |
|
45 | | - public function after (RequestInterface $request, ResponseInterface $response) |
46 | | - { |
47 | | - |
48 | | - $honeypot = Services::honeypot(new \Config\Honeypot()); |
49 | | - $honeypot->attachHoneypot($response); |
50 | | - } |
51 | 45 | } |
0 commit comments