Created
January 15, 2012 11:59
-
-
Save phawk/1615615 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
<?php | |
function login() | |
{ | |
// Set required fields | |
$this->form_validation->set_rules('email', 'Email', 'required'); | |
$this->form_validation->set_rules('password', 'Password', 'required'); | |
if ($this->form_validation->run() == FALSE) | |
{ | |
// Form has not yet been posted, load the login form page | |
$this->load->view('login_form'); | |
} | |
else | |
{ | |
// Form validation passed and has been posted | |
// Get the email field | |
$email = $this->input->post('email'); | |
// Get the password and sha1() encrypt it to compare it to the version in the database | |
$pass = sha1($this->input->post('password')); | |
// Authenticate the user | |
$user_id = $this->User_model->auth_user($email,$pass); | |
if($user_id) | |
{ | |
// Add the users id to the session. | |
$userdata = array( | |
'user_id' => $user_id | |
); | |
$this->session->set_userdata($userdata); | |
// Users first login, taken them to the details page. | |
redirect('/'); | |
} | |
else | |
{ | |
// The auth function return false, lets redirect back to this page so they can | |
// fill in the login for again. | |
redirect( current_url() ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment