[eluser]afro[/eluser]
Please help me out in debugging the following code below,
Here is the controller class.
Code:
<?php class Account extends Controller
{ function Account()
{ parent::Controller();
$this->load->library(array('form_validation', 'session')); $this->load->helper(array('url', 'form')); $this->load->model('account_model'); }
function index()
{ if($this->account_model->logged_in() === TRUE)
{ $this->dashboard(TRUE);
} else
{ $this->load->view('account/details');
} } function leave($condition = FALSE)
{
if($condition === TRUE OR $this->account_model->logged_in() === TRUE)
{ $this->load->view('leave');
} else
{ $this->load->view('home');
}
}
function login()
{ $this->form_validation->set_rules('username', 'Username','xss_clean|required|callback_username_check'); $this->form_validation->set_rules('password', 'Password','xss_clean|required|min_length[4]|max_length[12]|md5|callback_password_check'); $this->_username = $this->input->post('username');
$this->_password =md5($this->input->post('password'));
if($this->form_validation->run() == FALSE)
{ $this->load->view('home');
} else
{ $this->account_model->login();
$data['message'] ="You can now apply for the leave by filling in the fields below";
$this->load->view('leave', $data);
}
}
function register()
{ $this->form_validation->set_rules('username', 'Username', 'xss_clean|required');
$this->form_validation->set_rules('email', 'Email Address','xss_clean|required|valid_email|callback_email_exists'); $this->form_validation->set_rules('password', 'Password', 'xss_clean|required|min_length[4]|max_length[12]|matches[password_conf]|sha1'); $this->form_validation->set_rules('password_conf', 'Password Confirmation','xss_clean|required|matches[password]|sha1'); if($this->form_validation->run() == FALSE)
{ $this->load->view('account/register');
} else { $data['username'] = $this->input->post('username');
$data['email'] = $this->input->post('email');
$data['password'] = sha1($this->_salt . $this->input->post('password'));
if($this->account_model->create($data) === TRUE) { $data['message'] ="The user account has now been created! You can login ". anchor('account/login', 'here') . ".";
$this->load->view('account/success', $data);
}
else
{ $data['error'] ="There was a problem when adding your account to the database."; $this->load->view('account/error', $data);
} } }
function logout() {
$this->session->sess_destroy(); $data['message'] ="Good bye. You have been logout."; $this->load->view('home', $data);
}
function password_check()
{ $this->db->where('username', $this->_username);
$query= $this->db->get('users');
$result= $query->row_array();
if($result['password']==$this->_password);
{ return TRUE; } if($query->num_rows()==0)
{ $this->form_validation->set_message('password_check', 'Login faild!');
return FALSE;
}
}
function user_exists($user)
{ $query = $this->db->get_where('users', array('username' => $user));
if($query->num_rows() > 0)
{ $this->form_validation->set_message('user_exists','The %s already exists in our database, please use a different one.');
return FALSE;
} $query->free_result();
return TRUE;
}
function email_exists($email)
{
$query = $this->db->get_where('users', array('email' => $email)); if($query->num_rows() > 0)
{ $this->form_validation->set_message('email_exists','The %s already exists in our database, please use a different one.');
return FALSE;
} $query->free_result();
return TRUE;
}
}
The model class is here below.
?>
Code:
<?php class Account_model extends Model
{
function Account_model()
{ parent::Model();
}
function create($data)
{ if($this->db->insert('users', $data))
{ return TRUE;
} return FALSE;
}
function login()
{
$data = array( 'username' => $this->input->post('username'),
'logged_in' => TRUE );
$this->session->set_userdata($data);
} function logged_in()
{ if
($this->session->userdata('logged_in') == TRUE)
{ return TRUE; }
return FALSE; } } ?>
thank you