Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- /**
- * Description of login_form
- *
- * @author apocalipse89
- */
- class Login extends CI_Controller
- {
- public function __construct()
- {
- parent::__construct();
- //$this->load->model('User','user'); /* This call the model to retrieve data from db */
- }
- public function index()
- {
- if(!file_exists('application/views/login.php'))
- {
- show_404();
- }
- $this->load->library('form_validation');
- $this->load->helper('form');
- $this->load->helper('html');
- $this->load->library('session');
- $this->load->helper('url');
- $this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>');
- $this->form_validation->set_rules('username','username','trim|required|xss_clean');
- $this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check');
- if($this->form_validation->run() == FALSE)
- {
- /* Data to pass to view */
- $data['title'] = "User Access";
- $data['author'] = "Salvatore Mazzarino";
- $data['year'] = '34343434';
- $this->load->view('login',$data);
- /* $this->load->view('templates/_footer',$data);*/
- }
- else
- {
- redirect('home');
- }
- }
- public function pass_check($pass)
- {
- $result = array('id'=>123,'username'=>'test1');
- if(!empty($result))
- {
- $session_array = array('id'=> $result['id'], 'username'=> $result['username']); /* Create a session passing user data */
- $this->session->set_userdata('logged_in', $session_array);
- return TRUE;
- }
- else
- {
- $this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!");
- return FALSE;
- }
- }
- }
- /* END OF FILE */
Add Comment
Please, Sign In to add comment