-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReCaptcha.php
65 lines (57 loc) · 1.32 KB
/
ReCaptcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php namespace mjolnir\access;
require_once \app\CFS::dir('vendor/recaptcha').'/recaptchalib'.EXT;
/**
* @package mjolnir
* @category Access
* @author Ibidem Team
* @copyright (c) 2012, Ibidem Team
* @license https://github.com/ibidem/ibidem/blob/master/LICENSE.md
*/
class ReCaptcha
{
/**
* Outputs html required for recaptcha test.
*
* To customize add a script tag with
*
* var RecaptchaOptions = {
* theme : 'clean',
* tabindex : 2
* };
*
* @return string
*/
static function html()
{
$recaptcha_config = \app\CFS::config('mjolnir/auth')['recaptcha'];
if ( ! isset($recaptcha_config['public_key'], $recaptcha_config['private_key']))
{
throw new \app\Exception('ReCaptcha keys not set.');
}
return \recaptcha_get_html($recaptcha_config['public_key']);
}
/**
* Verify recaptcha is valid.
*
* @return string or null on success
*/
static function verify($recaptcha_challenge_field, $recaptcha_response_field)
{
$recaptcha_config = \app\CFS::config('mjolnir/auth')['recaptcha'];
$response = \recaptcha_check_answer
(
$recaptcha_config['private_key'],
$_SERVER['REMOTE_ADDR'],
$recaptcha_challenge_field,
$recaptcha_response_field
);
if ($response->is_valid)
{
return null;
}
else # error
{
return $response->error;
}
}
} # class