-
-
Save good-orbit/0647c46d3bdf78c1f037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CONTROLLER ( THE PORTION THAT IS RELEVENT ) | |
public function validate() { | |
//THIS LOADS THE MODEL THAT TAKES ALL THEIR INFO THEY TYPED AND INSERT IN THE DB | |
$this->load->model('auth_model'); | |
$query = $this->auth_model->validate(); | |
if($query) { | |
// IF THEIR INFO MATCHES UP, THEN START A SESSION WITH CI'S BUILT IN SESSION CLASS | |
$data = array( | |
'email' => $this->input->post('email'), | |
'password' => $this->input->post('password'), | |
'is_logged_in' => true | |
); | |
// AUTO LOADED SESSION CLASS | |
$this->session->set_userdata($data); | |
//THIS WILL TAKE THEM TO THE DASHBOARD PAGE IF EVERYTHING CHECKS OUT | |
redirect('home/dashboard'); | |
} | |
// IF INCORRECT THEN RELOAD THE FORM FOR NOW | |
else { | |
$this->index(); | |
} | |
} | |
//MODEL | |
<?php | |
class Auth_model extends CI_Model { | |
public function validate() { | |
//SEE IF THEIR INFO IS IN THE DB | |
$this->db->where('email', $this->input->post('email')); | |
$this->db->where('password', $this->input->post('password')); | |
$query = $this->db->get('users'); | |
//IF THE QUERY MATCHES THEN START RETURN TRUE AND DO OTHER STUFF | |
if($query->num_rows = 1) { | |
return true; | |
} | |
else{ | |
$this->login(); | |
} | |
} | |
} | |
//VIEW | |
<title>Login</title> | |
<div id="login_image"> | |
</div> | |
<h1 id="login_text_basic">Please Sign In</h1> | |
<div id="login_form"> | |
<?php | |
//THE FORM | |
echo form_open('home/dashboard'); | |
echo form_input('email', 'Email'); | |
echo form_password('password', 'Password'); | |
echo form_submit('submit', 'Login'); | |
echo form_close(); | |
?> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment