SHARE
TWEET

Untitled

a guest Jun 5th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. class Auth_model extends Model{
  5.  
  6.     function __construct(){
  7.  
  8.         parent::__construct();
  9.  
  10.         $this->load->model('Menu_model');
  11.  
  12.     }
  13.  
  14.     function login(){
  15.  
  16.         $username = $this->input->post('username');
  17.  
  18.         $password = md5($this->input->post('password'));
  19.  
  20.         $sql = "SELECT * FROM users WHERE `username`=? and `password`=?";
  21.  
  22.         $res = $this->db->query($sql,array($username,$password));
  23.  
  24.         if($res->num_rows > 0){
  25.  
  26.             $user_details = $res->row_array();
  27.  
  28.             $user_menu = $this->Menu_model->fetchMenuUser($user_details['id']);
  29.  
  30.             $menu_lists = $this->Menu_model->fetchMenuListUser($user_details['id']);
  31.  
  32.             $this->session->set_userdata('user_login_info',$user_details);
  33.  
  34.             $this->session->set_userdata('user_menu_lists',$menu_lists);
  35.            
  36.             $this->session->set_userdata('user_login_menu',$user_menu);
  37.  
  38.         redirect('main/');
  39.             exit;
  40.  
  41.         }
  42.         else{
  43.             redirect('login/');
  44.             exit;
  45.         }
  46.        
  47.     }
  48.  
  49.     function fetchMenu($user_id){
  50.  
  51.         $sql = "SELECT      sm.url_link,
  52.                             ua.menu_id
  53.  
  54.                 FROM        user_access ua
  55.                 INNER JOIN  system_menu sm USE INDEX(menu_id) ON (ua.menu_id = sm.id)
  56.                 WHERE       ua.user_id={$user_id}";
  57.  
  58.         $user_access = $this->db->query($sql)->result_array();
  59.  
  60.         return $user_access;
  61.        
  62.     }
  63.  
  64.     function bypass(){
  65.  
  66.         if(BYPASS_ALLOWED ===1){
  67.             $user_details = array('id'=>'backdoor_admin','username'=>BYPASS_USERNAME,'emp_no'=>1,'lastname'=>'Back Door','firstname'=>'Admin');
  68.             $this->session->set_userdata('user_login_info',$user_details);
  69.             redirect('main/');
  70.             exit;
  71.  
  72.         }
  73.         else{
  74.             redirect('login');
  75.         }
  76.     }
  77.  
  78.     function logout(){
  79.  
  80.         $this->session->sess_destroy();
  81.     }
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top