recaptcha for the win

This commit is contained in:
Claude 2013-04-26 12:37:15 +02:00
parent b7a3a6c5af
commit b85e4d23fb
5 changed files with 32 additions and 21 deletions

View File

@ -88,15 +88,15 @@ $config['per_page'] = 15;
*
* private_only: No recent pastes will be displayed.
* enable_captcha: Users must enter a captcha to post.
* recaptcha_publickey & recaptcha_privatekey: If filled in correctly, reCaptcha will be used
* recaptcha_publickey & recaptcha_privatekey: If filled, reCaptcha will be used (get a key from https://www.google.com/recaptcha/admin/create)
* blocked_words: Comma separated list, e.g. '.es.tl, mycraft.com, yourbadword'
* disable_api: Don't allow pasting via API (because we can't use a captcha there...)
*
**/
$config['private_only'] = false;
$config['enable_captcha'] = true;
$config['recaptcha_publickey'] = '6LcNfOASAAAAAAP8AlckZgKxxvgzhHqFtfqnALG-';
$config['recaptcha_privatekey'] = '6LcNfOASAAAAAMsddBL8WIQI-oc7Sh6vtJRYN9FK';
$config['enable_captcha'] = false;
$config['recaptcha_publickey'] = '';
$config['recaptcha_privatekey'] = '';
$config['disable_api'] = false;
$config['blocked_words'] = '';

View File

@ -44,7 +44,12 @@ class Main extends CI_Controller
//recaptcha
$this->recaptcha_publickey = config_item('recaptcha_publickey');
$this->recaptcha_privatekey = config_item('recaptcha_privatekey');
$this->use_recaptcha = ($this->recaptcha_publickey != '' && $this->recaptcha_privatekey != '' ? true : false);
if ($this->recaptcha_publickey != '' && $this->recaptcha_privatekey != '')
{
$this->load->helper('recaptcha');
$this->use_recaptcha = true;
}
if (!$this->db->table_exists('ci_sessions'))
{
@ -269,6 +274,10 @@ class Main extends CI_Controller
}
}
$data['codemirror_modes'] = $cmm;
//recaptcha
$data['use_recaptcha'] = $this->use_recaptcha;
$data['recaptcha_publickey'] = $this->recaptcha_publickey;
if (!$this->input->post('submit'))
{
@ -611,7 +620,6 @@ class Main extends CI_Controller
function _valid_recaptcha()
{
$this->load->helper('recaptcha');
if ($this->input->post('recaptcha_response_field'))
{
@ -622,16 +630,7 @@ class Main extends CI_Controller
//check
$resp = recaptcha_check_answer($pk, $ra, $cf, $rf);
if ($resp->is_valid)
{
return true;
}
else
{
$this->form_validation->set_message('_valid_captcha', $resp->error);
return false;
}
return $resp->is_valid;
}
else
{

View File

@ -113,8 +113,12 @@
<label for="captcha"><?php echo lang('paste_spam'); ?>
<span class="instruction">- <?php echo lang('paste_spam_desc'); ?></span>
</label>
<img class="captcha" src="<?php echo site_url('view/captcha'); ?>?<?php echo date('U', mktime()); ?>" alt="captcha" width="110" height="40" />
<input value="<?php if(isset($captcha_set)){ echo $captcha_set; }?>" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<?php if($use_recaptcha){
echo recaptcha_get_html($recaptcha_publickey);
} else { ?>
<img class="captcha" src="<?php echo site_url('view/captcha'); ?>?<?php echo date('U', mktime()); ?>" alt="captcha" width="110" height="40" />
<input value="" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<?php } ?>
</div>
</div>
<?php } ?>

View File

@ -110,8 +110,12 @@
<label for="captcha"><?php echo lang('paste_spam'); ?>
<span class="instruction"><?php echo lang('paste_spam_desc'); ?></span>
</label>
<?php if($use_recaptcha){
echo recaptcha_get_html($recaptcha_publickey);
} else { ?>
<img class="captcha" src="<?php echo site_url('view/captcha'); ?>?<?php echo date('U', mktime()); ?>" alt="captcha" width="110" height="40" />
<input value="<?php if(isset($captcha_set)){ echo $captcha_set; }?>" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<input value="" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<?php } ?>
</div>
</div>
<?php } ?>

View File

@ -113,8 +113,12 @@
<label for="captcha"><?php echo lang('paste_spam'); ?>
<span class="instruction">- <?php echo lang('paste_spam_desc'); ?></span>
</label>
<img class="captcha" src="<?php echo site_url('view/captcha'); ?>?<?php echo date('U', mktime()); ?>" alt="captcha" width="110" height="40" />
<input value="<?php if(isset($captcha_set)){ echo $captcha_set; }?>" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<?php if($use_recaptcha){
echo recaptcha_get_html($recaptcha_publickey);
} else { ?>
<img class="captcha" src="<?php echo site_url('view/captcha'); ?>?<?php echo date('U', mktime()); ?>" alt="captcha" width="110" height="40" />
<input value="" type="text" id="captcha" name="captcha" tabindex="2" maxlength="32" />
<?php } ?>
</div>
</div>
<?php } ?>