Advertisement
jamboljack

Login Controller

May 23rd, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. public function validasi()
  2.     {
  3.         $username = $this->input->post('username', 'true');
  4.         $password = $this->input->post('password', 'true');
  5.        
  6.         $temp_user = $this->login_model->get_user($username)->row();
  7.         $num_user = count($temp_user);
  8.        
  9.         $this->form_validation->set_rules('username', 'Username', 'trim|required');
  10.         $this->form_validation->set_rules('password', 'Password', 'trim|required');
  11.        
  12.         if ($this->form_validation->run() == FALSE)
  13.         {
  14.             $this->load->view('login_view');
  15.         }
  16.         else
  17.         {
  18.             if ($num_user == 0)
  19.             { // Username Tidak Terdaftar
  20.                 $this->session->set_flashdata('notification','Username Anda tidak Terdaftar, Hubungi Administrator !');
  21.                 redirect(site_url('login'));
  22.                 echo '1';
  23.             } elseif ($num_user > 0)
  24.             { // Username Terdaftar            
  25.                 $temp_account = $this->login_model->check_user_account($username, sha1($password))->row();
  26.                 $num_account = count($temp_account);
  27.        
  28.                 if ($num_account > 0)
  29.                 {  
  30.                     $array_item = array('username'  => $temp_account->user_username,
  31.                                         'nama'      => $temp_account->user_name,
  32.                                         'level'     => $temp_account->user_level,                                      
  33.                                         'logged_in_hrd' => TRUE
  34.                                         );
  35.                    
  36.                     $this->session->set_userdata($array_item);                                                 
  37.                     if ($this->session->userdata('level') == 'Admin') // Admin
  38.                     {
  39.                         redirect(site_url('home'));
  40.                     }                  
  41.                 }
  42.                 else
  43.                 {
  44.                     $this->session->set_flashdata('notification','LOGIN GAGAL !!, Username and Password Anda Salah.');
  45.                     redirect(site_url('login'));                   
  46.                 }              
  47.             }
  48.         }      
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement