Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1.  function GetUsers($options=array())
  2.      {
  3.          if(isset($options['userId']))
  4.            $this->db->where('userId',$options['userId']);
  5.              
  6.          if(isset($options['userEmail']))
  7.            $this->db->where('userEmail',$options['userEmail']);
  8.  
  9.             //echo "salt=".$this->config->item('SALT');
  10.             //echo "password=".$options['userPassword'];
  11.                        
  12.          if(isset($options['userPassword']))
  13.              $this->db->where('userPassword',dohash($this->config->item('SALT').$options['userPassword'].$this->config->item('SALT')));
  14.            
  15.          if(isset($options['userStatus']))
  16.              $this->db->where('userStatus',$options['userStatus']);
  17.          if(isset($options['userType']))
  18.              $this->db->where('userType',$options['userType']);
  19.                
  20.          //Limit / offset  
  21.          if(isset($options['limit']) && isset($options['offset']))
  22.              $this->db->limit($options['limit'],$options['offset']);
  23.          else if(isset($options['limit']))
  24.              $this->db->limit($options['limit']);          
  25.            
  26.          if(isset($options['sortBy']) && isset($options['sortDirection']))
  27.            $this->db->order_by($options['sortBy'],$options['sortDirection']);
  28.        
  29.          if(!isset($options['userStatus'])) $this->db->where('userStatus !=','deleted');
  30.        
  31.          $query = $this->db->get('users');//query
  32.          
  33.          echo $this->db->last_query();
  34.          
  35.          if(isset($options['userId']) || isset($options['userEmail']))
  36.          {
  37.              //echo "<br />";
  38.              //print_r($query->row(0));exit;
  39.              
  40.            return $query->row(0);
  41.          }
  42.          echo "not here";
  43.          return $query->result();
  44.      }//end func
  45.      
  46.      function _default($defaults,$options)
  47.      {
  48.           return array_merge($defaults,$options);
  49.      }
  50.    
  51.      /*Authentication methods*/
  52.      function Login($options=array())
  53.      {
  54.          if(!$this->_required(array('userEmail','userPassword'),$options))//check the required options of email and pass aggainst provided $options.
  55.          {
  56.            return false;
  57.          }
  58.          
  59.          $user = $this->GetUsers(array('userEmail' => $options['userEmail'],
  60.                                                                      'userPassword' => dohash( $this->config->item('SALT').
  61.                                                                                                                        $options['userPassword'].
  62.                                                                                                                        $this->config->item('SALT')),
  63.                                                                      'userStatus' => 'active'));
  64.          
  65.          print_r($user);exit;
  66.          //Returns empty array() which == false
  67.          if(!$user)
  68.              return false;
  69.        
  70.          //Set session vars
  71.          $this->session->set_userdata('userEmail',$user->userEmail);
  72.          $this->session->set_userdata('userId',$user->userId);
  73.          $this->session->set_userdata('userType',$user->userType);
  74.          $this->session->set_userdata('userStatus',$user->userStatus);
  75.          
  76.          return true;
  77.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement