Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class user
- {
- public $_info = array();
- public $_loggedIn = false;
- public $_loggedInFB = false;
- private $_username;
- private $_password;
- private $_facebook_id;
- // what info do we want passed in initially? The current session information
- public function __construct($username='', $password='', $facebook_id='')
- {
- $this->_username = $username;
- $this->_password = $password;
- $this->_facebook_id = $facebook_id;
- $this->_info = $this->login();
- $this->_loggedIn = ($this->_info) ? true : false;
- }
- // user can login if not logged in
- public function login()
- {
- if(!$_SESSION['uinfo'])
- {
- // if user is logging in through facebook check the database to see if they are already registered in our database
- if($this->_facebook_id)
- {
- $check = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE mem_oauth_provider = 'facebook' && mem_oauth_uid = '".$this->_facebook_id."' LIMIT 1"));
- // if the user has a member id reister the sesssion, other wise do nothing
- if($check['mem_id'])
- {
- $this->sessionRegister($check);
- }
- } elseif($this->_username && $this->_password)
- {
- // person is entering a username and password lets check it against the database
- $cleanUsername = addslashes($this->_username);
- $cleanPassword = md5($this->_password);
- $check = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE mem_nick = '".$cleanUsername."' && mem_password = '".$cleanPassword."' LIMIT 1"));
- // if there is an id for the user let's set the session up
- if($check['mem_id'])
- {
- $this->sessionRegister($check);
- }
- }
- return $this->_info;
- } else {
- return $_SESSION['uinfo'];
- }
- }
- // logout method
- public function logout()
- {
- unset($_SESSION[uinfo]);
- $this->_loggedIn = false;
- }
- // register a session for people being logged in
- private function sessionRegister($memberArray)
- {
- $this->_info = $_SESSION['uinfo'] = array(
- 'id' => $memberArray['mem_id'],
- 'email' => $memberArray['mem_email'],
- 'username' => $memberArray['mem_nick'],
- 'active' => $memberArray['mem_active'],
- 'level' => $memberArray['mem_level'],
- 'facebook_id' => $memberArray['mem_oauth_uid'],
- );
- $this->_loggedIn = true;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement