fanjava

Controller login.php

May 8th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login extends CI_Controller
  4. {
  5.     function __construct()
  6.     {
  7.         parent::__construct();
  8.     }
  9.    
  10.     function index()
  11.     {
  12.         $data_session = $this->session->all_userdata();
  13.         if(!empty($data_session)){
  14.             redirect('admin/main');
  15.         }else{
  16.             $this->load->view('login_view');
  17.         }
  18.     }
  19.    
  20.     function dologin()
  21.     {
  22.         $rules = array(
  23.             array(
  24.                 'field' => 'username',
  25.                 'label' => 'Username',
  26.                 'rules' => 'required|callback_cek_username'
  27.             ),
  28.             array(
  29.                 'field' => 'password',
  30.                 'label' => 'Password',
  31.                 'rules' => 'required'
  32.             )
  33.         );
  34.        
  35.         $this->form_validation->set_rules($rules);
  36.         $this->form_validation->set_error_delimiters('<div class="alert alert-error">','</div>');
  37.        
  38.         $data = array(
  39.             'username' => $this->input->post('username'),      
  40.             'password' => $this->input->post('password')
  41.         );
  42.        
  43.         if($this->form_validation->run() == FALSE){
  44.             $this->load->view('login_view');
  45.         }else{
  46.             //set session
  47.             $this->session->set_userdata($data['username']);
  48.             redirect('admin/main');
  49.         }
  50.     }
  51.    
  52.     function cek_username($str){
  53.         if($str != 'admin'){
  54.             $this->form_validation->set_message('cek_username','%s Salah! Coba Lagi.');
  55.             return FALSE;
  56.         }else{
  57.             return TRUE;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment