Merge pull request #239 from modInfo/captcha

Google new recaptcha
This commit is contained in:
Claude 2015-01-27 12:57:34 +01:00
commit 97dbfa30e4
2 changed files with 27 additions and 9 deletions

View File

@ -41,6 +41,7 @@ class Main extends CI_Controller
parent::__construct(); parent::__construct();
$this->output->enable_profiler(false); $this->output->enable_profiler(false);
$this->load->model('languages'); $this->load->model('languages');
$this->load->library('curl');
if (config_item('require_auth')) if (config_item('require_auth'))
{ {
@ -697,16 +698,29 @@ class Main extends CI_Controller
function _valid_recaptcha() function _valid_recaptcha()
{ {
if ($this->input->post('recaptcha_response_field')) if ($this->recaptcha_privatekey == null || $this->recaptcha_privatekey == '') {
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
}
if ($this->input->post('g-recaptcha-response'))
{ {
$pk = $this->recaptcha_privatekey; $pk = $this->recaptcha_privatekey;
$ra = $_SERVER['REMOTE_ADDR']; $ra = $_SERVER['REMOTE_ADDR'];
$cf = $this->input->post('recaptcha_challenge_field'); $rf = trim($this->input->post('g-recaptcha-response'));
$rf = $this->input->post('recaptcha_response_field');
//check $url="https://www.google.com/recaptcha/api/siteverify?secret=".$pk."&response;=".$rf."&remoteip;=".$ra;
$resp = recaptcha_check_answer($pk, $ra, $cf, $rf); $response = $this->curl->simple_get($url);
return $resp->is_valid; $status= json_decode($response, true);
if($status['success'])
{
$recaptcha_response->is_valid = true;
}
else
{
$recaptcha_response->is_valid = false;
}
return $recaptcha_response;
} }
else else
{ {

View File

@ -119,13 +119,17 @@ function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
if ($error) { if ($error) {
$errorpart = "&amp;error=" . $error; $errorpart = "&amp;error=" . $error;
} }
return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> return '<script src=\'https://www.google.com/recaptcha/api.js\'></script>
<div class="g-recaptcha" data-sitekey="' . $pubkey . '"></div>';
/*return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
<noscript> <noscript>
<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>'; </noscript>';*/
} }