I would prefer not to write any new functions if possible and tie it into my existing login function.
Here is the model and controller for said module:
//MODEL
public function validate_home_login($data)
{
// TAKING THE DATA FROM THE MODEL AND CHECKING IT AGAINST THE STORED INFO IN THE DB
$query = $this->db->where($data)->get('users', '1');
if($query->row())
{
return $query->row();
$valid_email = $row->email;
}
}
//CONTROLLER
public function validate_credentials_login()
{
$this->load->library('session');
$this->load->helper(array('form','url'));
$this->load->model('user_model', 'um');
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email|');
$this->form_validation->set_rules('password_login', 'Password', 'trim|required');
if ( $this->form_validation->run() === TRUE )
{
$user = $this->um->validate_home_login(array('email' => $this->input->post('email_login')));
// if $user exists
if ( $user ) {
// if the password is correct
if ( $user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login') )
{
$this->session->set_userdata(array('email' => $this->input->post('email_login')));
redirect('account/dashboard');
// if the password is incorrect
}else{
$this->form_validation->run() == FALSE;
$data['password_error'] = 'The password field is invalid.';
}
// if $user doesn't exist
}else{
$this->form_validation->run() == FALSE;
$data['email_error'] = 'This email is invalid.';
}
}
$data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}
thanks in advance
Edited by RalphLeMouf, 05 December 2012 - 01:52 PM.












