jamboljack

Login (Controller)

May 19th, 2014
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login extends CI_Controller {
  4.     function __construct() {
  5.         parent::__construct(); 
  6.         $this->load->model('a/login_model');   
  7.     }
  8.    
  9.     public function index() {
  10.         if($this->session->userdata('logged_in')) {
  11.             redirect('home', 'refresh');
  12.         } else {
  13.             $this->load->view('a/login_form');
  14.         }
  15.     }
  16.    
  17.     public function validasi() {
  18.         $email = $this->input->post('email', 'true');
  19.         $password = $this->input->post('password', 'true');
  20.        
  21.         $temp_account = $this->login_model->check_user_account($email, md5($password))->row();
  22.         $num_account = count($temp_account);
  23.        
  24.         $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  25.         $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|max_length[128]|xss_clean');
  26.        
  27.         if ($this->form_validation->run() == FALSE) {
  28.             $this->load->view('a/login_form');
  29.         } else {
  30.             if ($num_account > 0) {
  31.                 $array_item = array('email' => $temp_account->email,
  32.                                     'nama_lengkap' => $temp_account->nama_lengkap,
  33.                                     'logged_in' => TRUE);
  34.                 $this->session->set_userdata($array_item);
  35.                 // Sukses Admin
  36.                 redirect(site_url('a/home'));                    
  37.             } else {
  38.                 $this->session->set_flashdata('notification','Email dan Pasword Salah.');
  39.                 redirect(site_url('a/login'));
  40.             }
  41.         }      
  42.     }  
  43. }
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment