Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. <?php
  2. defined ('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. *
  5. */
  6. class Login extends CI_Controller
  7. {
  8.    
  9.     function __construct()
  10.     {
  11.         parent::__construct();
  12.  
  13.         $this->load->model('model_login');
  14.     }
  15.  
  16.     public function index()
  17.     {
  18.         $data = array(
  19.             'action' => site_url('login/login'),
  20.             'username' => set_value('username'),
  21.             'password' => set_value('password'),
  22.             'captcha' => $this->recaptcha->getWidget(),
  23.             'script_captcha' => $this->recaptcha->getScriptTag(),
  24.         );
  25.  
  26.         $this->load->view('login',$data);
  27.     }
  28.  
  29.     public function login()
  30.     {
  31.         if (isset($_POST['login'])) {
  32.             $this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
  33.  
  34.             $username = $this->input->post('username',true,'trim|required');
  35.             $password = $this->input->post('password',true,'trim|required');
  36.  
  37.             $recaptcha = $this->input->post('g-recaptcha-response');
  38.             $response = $this->recaptcha->verifyResponse($recaptcha);
  39.  
  40.             $cek = $this->model_login->proses($username,$password);
  41.             $hasil = count($cek);
  42.  
  43.             if ($hasil > 0 || $this->form_validation->run() == TRUE || !isset($response['success']) || $response['success'] == true) {
  44.                 $logintest = $this->db->get_where('users',array('username'=>$username,'password'=>$password))->row();
  45.  
  46.                 $data = array('success' => true,
  47.                     'nama'=>$logintest->nama,
  48.                     'username'=>$logintest->username
  49.                 );
  50.  
  51.                 $this->session->set_userdata($data);
  52.  
  53.                 if ($logintest->level == 'admin') {
  54.                     redirect('home_admin');
  55.                 }elseif ($logintest->level == 'user') {
  56.                     redirect('home_user');
  57.                 }
  58.             }else{
  59.                 redirect('index','refresh');
  60.             }
  61.  
  62.             /*if ($hasil > 0) {
  63.                 $logintest = $this->db->get_where('users',array('username'=>$username,'password'=>$password))->row();
  64.  
  65.                 $data = array('success' => true,
  66.                     'nama'=>$logintest->nama,
  67.                     'username'=>$logintest->username
  68.                 );
  69.  
  70.                 $this->session->set_userdata($data);
  71.  
  72.                 if ($logintest->level == 'admin') {
  73.                     redirect('home_admin');
  74.                 }elseif ($logintest->level == 'user') {
  75.                     redirect('home_user');
  76.                 }
  77.             }else{
  78.                 redirect('index','refresh');
  79.             }*/
  80.  
  81.             //$this->form_validation->set_rules('username',' ','trim|required');
  82.             //$this->form_validation->set_rules('password',' ','trim|required');
  83.  
  84.         }
  85.     }
  86.  
  87.     function home_admin()
  88.     {
  89.         $this->load->view('admin',$data);
  90.     }
  91.  
  92.     function home_user()
  93.     {
  94.         $this->load->view('user',$data);
  95.     }
  96.  
  97.     function logout()
  98.     {
  99.         $this->session->sess_destroy();
  100.         redirect('index');
  101.     }
  102. }
  103. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement