1 | <?php |
||
13 | class HCaptchaField extends FormField |
||
14 | { |
||
15 | /** |
||
16 | * HCaptcha Site Key |
||
17 | * @config HCaptchaField.site_key |
||
18 | */ |
||
19 | private static $site_key; |
||
20 | |||
21 | /** |
||
22 | * HCaptcha Secret Key |
||
23 | * @config HCaptchaField.secret_key |
||
24 | */ |
||
25 | private static $secret_key; |
||
26 | |||
27 | /** |
||
28 | * HCaptcha Site Key |
||
29 | * Configurable via Injector config |
||
30 | */ |
||
31 | protected $_siteKey; |
||
32 | |||
33 | /** |
||
34 | * HCaptcha Site Key |
||
35 | * Configurable via Injector config |
||
36 | */ |
||
37 | protected $_secretKey; |
||
38 | |||
39 | /** |
||
40 | * Captcha theme, currently options are light and dark |
||
41 | * @var string |
||
42 | * @default light |
||
43 | */ |
||
44 | private static $default_theme = 'light'; |
||
45 | |||
46 | /** |
||
47 | * Captcha theme, currently options are light and dark |
||
48 | * @var string |
||
49 | */ |
||
50 | private $_captchaTheme; |
||
51 | |||
52 | /** |
||
53 | * Creates a new HCaptcha field. |
||
54 | * @param string $name The internal field name, passed to forms. |
||
55 | * @param string $title The human-readable field label. |
||
56 | * @param mixed $value The value of the field (unused) |
||
57 | */ |
||
58 | public function __construct($name, $title = null, $value = null) |
||
65 | |||
66 | /** |
||
67 | * Adds in the requirements for the field |
||
68 | * @param array $properties Array of properties for the form element (not used) |
||
69 | * @return DBHTMLText Rendered field template |
||
70 | */ |
||
71 | public function Field($properties = []) |
||
88 | |||
89 | /** |
||
90 | * Validates the captcha against the hCaptcha API |
||
91 | * @param Validator $validator Validator to send errors to |
||
92 | * @return bool Returns boolean true if valid false if not |
||
93 | */ |
||
94 | public function validate($validator) |
||
111 | |||
112 | /** |
||
113 | * Validates the captcha against the hCaptcha API |
||
114 | * @return bool Returns boolean true if valid false if not |
||
115 | */ |
||
116 | private function processCaptcha() |
||
159 | |||
160 | /** |
||
161 | * Gets the site key configured via HCaptchaField.site_key this is used in the template |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getSiteKey() |
||
168 | |||
169 | /** |
||
170 | * Gets the secret key configured via HCaptchaField.secret_key |
||
171 | * @return string |
||
172 | */ |
||
173 | private function getSecretKey() |
||
177 | |||
178 | /** |
||
179 | * Setter for _siteKey to allow injector config to override the value |
||
180 | * @param string $key |
||
181 | */ |
||
182 | public function setSiteKey($key) |
||
186 | |||
187 | /** |
||
188 | * Setter for _secretKey to allow injector config to override the value |
||
189 | * @param string $key |
||
190 | */ |
||
191 | public function setSecretKey($key) |
||
195 | |||
196 | /** |
||
197 | * Gets the form's id |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getFormID() |
||
204 | |||
205 | /** |
||
206 | * Sets the theme for this captcha |
||
207 | * @param string $value Theme to set it to, currently the api supports light and dark |
||
208 | * @return NocaptchaField |
||
209 | */ |
||
210 | public function setTheme($value) |
||
216 | |||
217 | /** |
||
218 | * Gets the theme for this captcha |
||
219 | * @return string |
||
220 | */ |
||
221 | public function getCaptchaTheme() |
||
225 | } |
||
226 |