All pastes #2460107 Raw Edit

Stuff

public unlisted text v1 · immutable
#2460107 ·published 2013-09-30 11:58 UTC
rendered paste body
function __construct()
	{
		parent::__construct();
		
		$this->session_control();
	}

public function session_control()
	{
		$this->_user = $this->session->userdata('user_name');
		if(empty($this->_user))
		{
			$fb_config = array(
				'appId'  => 'appid',
				'secret' => 'secret'
			);

			$this->load->library('facebook', $fb_config);
			$this->user = $this->facebook->getUser();
			
			/* Debug
			$this->session->sess_destroy();
			*/
		
		
			if(isset($this->user) && !empty($this->user))
			{
				$this->load->model('facebook_user_model');
				$user_profile = $this->facebook->api('/me');
				$_is_user_exists = $this->facebook_user_model->_is_user_exists($user_profile["username"]);
				if($_is_user_exists == 0)
				{
					$token = array(
						"face_id" => $user_profile["id"],
						"username" => $user_profile["username"],
						"name" => $user_profile["name"]
						
					);
					$_add_user = $this->facebook_user_model->_add_user($token);
					if($_add_user == 0)
						echo "Kullanıcı Veritabanına Eklenemedi";
						
					$session_token = array(
						"user_id" => $_add_user,
						"user_name" => $user_profile["username"]
					);
					$this->session->set_userdata($session_token);
				}
				else
				{
					$session_token = array(
						"user_id" => $_is_user_exists,
						"user_name" => $user_profile["username"]
					);
					$this->session->set_userdata($session_token);
				}
			}
		}
	}