Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. class user
  4. {
  5.     public $_info = array();
  6.     public $_loggedIn = false;
  7.     public $_loggedInFB = false;
  8.    
  9.     private $_username;
  10.     private $_password;
  11.     private $_facebook_id;
  12.    
  13.    
  14.    
  15.    
  16.     // what info do we want passed in initially? The current session information
  17.     public function __construct($username='', $password='', $facebook_id='')
  18.     {
  19.         $this->_username    = $username;
  20.         $this->_password    = $password;
  21.         $this->_facebook_id = $facebook_id;
  22.         $this->_info = $this->login();
  23.         $this->_loggedIn = ($this->_info) ? true : false;
  24.     }
  25.    
  26.    
  27.    
  28.    
  29.    
  30.     // user can login if not logged in
  31.     public function login()
  32.     {
  33.         if(!$_SESSION['uinfo'])
  34.         {
  35.             // if user is logging in through facebook check the database to see if they are already registered in our database
  36.             if($this->_facebook_id)
  37.             {
  38.                 $check = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE mem_oauth_provider = 'facebook' && mem_oauth_uid = '".$this->_facebook_id."' LIMIT 1"));
  39.                
  40.                 // if the user has a member id reister the sesssion, other wise do nothing
  41.                 if($check['mem_id'])
  42.                 {
  43.                     $this->sessionRegister($check);
  44.                 }
  45.                
  46.             } elseif($this->_username && $this->_password)
  47.             {
  48.                 // person is entering a username and password lets check it against the database
  49.                 $cleanUsername = addslashes($this->_username);
  50.                 $cleanPassword = md5($this->_password);
  51.                 $check = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE mem_nick = '".$cleanUsername."' && mem_password = '".$cleanPassword."' LIMIT 1"));
  52.                
  53.                 // if there is an id for the user let's set the session up
  54.                 if($check['mem_id'])
  55.                 {
  56.                     $this->sessionRegister($check);
  57.                 }
  58.             }
  59.            
  60.             return $this->_info;
  61.            
  62.         } else {
  63.            
  64.             return $_SESSION['uinfo'];
  65.         }
  66.     }
  67.    
  68.    
  69.    
  70.    
  71.    
  72.     // logout method
  73.     public function logout()
  74.     {
  75.         unset($_SESSION[uinfo]);
  76.         $this->_loggedIn = false;
  77.     }  
  78.    
  79.    
  80.    
  81.    
  82.    
  83.     // register a session for people being logged in
  84.     private function sessionRegister($memberArray)
  85.     {
  86.         $this->_info = $_SESSION['uinfo'] = array(
  87.                                                      'id'              => $memberArray['mem_id'],
  88.                                                      'email'           => $memberArray['mem_email'],
  89.                                                      'username'        => $memberArray['mem_nick'],
  90.                                                      'active'          => $memberArray['mem_active'],
  91.                                                      'level'           => $memberArray['mem_level'],
  92.                                                      'facebook_id'     => $memberArray['mem_oauth_uid'],
  93.                                                      );
  94.        
  95.         $this->_loggedIn = true;
  96.        
  97.     }
  98.        
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement