[eluser]The Wizard[/eluser]
Hello friends
ive fixed the code, the propper one looks like:
Code:
<?php
class User extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library( 'session' );
$this->load->library( 'parser' ); /* load template parser */
$this->load->model ( 'User_model' );
$this->load->database();
}
function register_process( $data )
{
/* add additional data, or form the data like you want. */
$data['status'] = "Pending";
$data['activation'] = 31337 + rand( 0, 666666999);
$this->load->helper('date');
$data['datetime'] = mdate( "%Y-%m-%d %H:%i:%s" );
$result_register = $this->User_model->User_Register( $data );
return $result_register;
}
function register ()
{
$this->load->helper( 'form' );
$this->load->helper( 'url' );
$this->load->library('validation');
/* by default the error messages are displayed in <p> tags. */
$this->validation->set_error_delimiters('<div class="error">', '</div>');
//$rules['username'] = "callback_database_check";
$rules['username'] = "required|min_length[5]|max_length[12]|callback_check_username";
$rules['password'] = "required|matches[passconf]";
$rules['passconf'] = "required";
$rules['email'] = "required|valid_email||callback_check_email";
$this->validation->set_rules($rules);
$check_rules = $this->validation->run();
if ( ($check_rules == false) )
{
$fields['username'] = 'Username';
$fields['password'] = 'Password';
$fields['passconf'] = 'Password Confirmation';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
$this->load->view('register_new.php');
}
else
{
$data['username'] = $this->input->post ('username');
$data['password'] = $this->input->post ('password');
$data['email'] = $this->input->post ('email');
$status = $this->register_process( $data );
$status_info = $status['status'];
if ( $status_info == 'Success' )
{
$this->load->view('register_success.php');
}
elseif ( $status_info == 'Error' )
{
}
}
}
function check_username( $data )
{
if ( $this->User_model->User_Check( $data, 'username') == true )
{
$this->validation->set_message('check_username', "The Username: '$data' is allready taken, please chose another one.");
return FALSE;
}
else
{
return TRUE;
}
}
function check_email( $data )
{
if ( $this->User_model->User_Check( $data, 'email') == true )
{
$this->validation->set_message('check_email', "The Email address '$data' has been used to sign-up before. ");
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
the model:
Code:
<?php
/*
WARNING!
Fields must be XSS filtered BEFORE calling this routine.
They should have been filtered IN the controller.
*/
class User_model extends Model {
function User_model()
{
parent::Model();
$this->load->database();
}
function User_Check ( $data, $type )
{
if ( $data == '' )
{
return false;
exit ();
}
$this->db->select ('id');
$this->db->from ('users');
if ( $type == 'email')
{
$this->db->where ( 'email', $data );
}
elseif ( $type == 'username')
{
$this->db->where ( 'username', $data );
}
$query = $this->db->count_all_results();
if ($query > 0)
{
/* email exists */
return true;
}
else
{
return false;
}
}
function UTEST ()
{
return false;
}
function User_Register( $data )
{
$this->db->insert('users', $data);
return array(
"status" => "Success",
"error_code" => "0"
);
}
}
?>