[eluser]Unknown[/eluser]
Hi,
I'm pretty new to Codeigniter and have been trying to debug and figure out what is wrong with my reCaptcha implementation. Maybe someone here can help me?
Basically the problem is when I run the
check_captcha() function I don't feed it with the values it wants; and I can't figure out why.
This is built on the reCaptcha implementation posted here in the forum/wiki
Please tell me if there is anything missing. Thankful for all help. I have attached my whole project.
NOTE: It works when using the nocode part of the implementation. But I don't want that.
reCaptcha-HTML:
Code:
[removed]
var RecaptchaOptions = {
theme:"<?= $theme ?>",
lang:"<?= $lang ?>"
};
[removed]
[removed][removed]
<noscript>
<iframe src="<?= $server ?>/noscript?lang=<?= $lang ?>&k=<?= $key.$errorpart ?>" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
Login/signup controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('recaptcha');
$this->load->library('form_validation');
$this->load->helper('form');
$this->lang->load('recaptcha');
}
function index(){
$data['title'] = "Moosic - Login";
$data['heading'] = "Login to Moosic";
$data['main_content'] = 'login_view';
$this->load->view('includes/main_template', $data);
}
function validate_credentials() {
// Load models
$this->load->model('Users_model');
$query = $this->Users_model->validate();
if($query){ // if session validates
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => TRUE
);
$this->session->set_userdata($data);
redirect('posts');
} else {
// TODO Add error message
$this->index();
}
}
function logout(){
$this->session->sess_destroy();
redirect('posts');
}
function signup(){
$data['title'] = "Moosic - Signup";
$data['heading'] = "Signup for Moosic";
$data['recaptcha'] = array('html'=>$this->recaptcha->get_html());
$data['main_content'] = 'login_signup_view';
$this->load->view('includes/main_template', $data);
}
function signup_user(){
// field name, error messages, validation rules
$this->form_validation->set_rules('first_name', 'First name', 'trim|required|max_length[25]');
$this->form_validation->set_rules('last_name', 'Last name', 'trim|required|max_length[25]');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email|max_length[50]');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|max_length[32]');
$this->form_validation->set_rules('password_confirm', 'Confirm password', 'trim|required|matches[password]');
// DEBUG LOG
var_dump($this->input->post(NULL, FALSE));
//log_message('debug','Recaptcha:$_POST Debug @before validation->run() '.print_r($this->input->post(NULL, FALSE)).')');
//------------
// ReCaptcha
$this->form_validation->set_rules('recaptcha_response_field', 'lang:recaptcha_field_name', 'callback_check_captcha');
if($this->form_validation->run() == FALSE){
$this->signup();
} else {
$this->load->model('Users_model');
if($query = $this->Users_model->create_user()){
redirect('login');
} else {
$this->signup();
}
}
}
function check_captcha($str) {
if ($this->recaptcha->check_answer($this->input->ip_address(),$this->input->post('recaptcha_challange_field'),$str)) {
return TRUE;
} else {
$this->form_validation->set_message('check_captcha',$this->lang->line('recaptcha_incorrect_response'));
return FALSE;
}
}
}
?>