1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <contact@terryl.in>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 * 
10
 * php version 7.1.0
11
 * 
12
 * @category  Web-security
13
 * @package   Shieldon
14
 * @author    Terry Lin <contact@terryl.in>
15
 * @copyright 2019 terrylinooo
16
 * @license   https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
17
 * @link      https://github.com/terrylinooo/shieldon
18
 * @see       https://shieldon.io
19
 */
20

21
declare(strict_types=1);
22

23
namespace Shieldon\Firewall\Captcha;
24

25
use Shieldon\Firewall\Captcha\CaptchaProvider;
26

27
use function Shieldon\Firewall\get_request;
28
use function Shieldon\Firewall\unset_superglobal;
29

30
/**
31
 * Basic form.
32
 */
33
class Foundation extends CaptchaProvider
34
{
35
    /**
36
     * Constructor.
37
     *
38
     * It will implement default configuration settings here.
39
     *
40
     * @array $config
41
     *
42
     * @return void
43
     */
44 3
    public function __construct()
45
    {
46 3
        parent::__construct();
47
    }
48

49
    /**
50
     * Response the result.
51
     *
52
     * @return bool
53
     */
54 3
    public function response(): bool
55
    {
56 3
        $postParams = get_request()->getParsedBody();
57
 
58 3
        if (empty($postParams['shieldon_captcha'])) {
59 3
            return false;
60
        }
61

62 3
        $flag = false;
63

64 3
        if ($postParams['shieldon_captcha'] === 'ok') {
65 3
            $flag = true;
66
        }
67

68
        // Prevent detecting POST method on RESTful frameworks.
69 3
        unset_superglobal('shieldon_captcha', 'post');
70

71 3
        return $flag;
72
    }
73

74
    /**
75
     * Output a required HTML.
76
     *
77
     * @return string
78
     */
79 3
    public function form(): string
80
    {
81 3
        $html  = '<input id="shieldon-captcha-example" type="hidden" name="shieldon_captcha">';
82 3
        $html .= '<script>document.getElementById("shieldon-captcha-example").value = "ok";</script>';
83

84 3
        return $html;
85
    }
86
}

Read our documentation on viewing source code .

Loading