Exemplo n.º 1
0
	function isLinked(){
		JRequest::checkToken( 'get' ) or die( 'Invalid Token' );
		$db = JFactory::getDBO();
		$uid = JRequest::getVar('fbId','','get');
		$query = "SELECT userId FROM ".$db->nameQuote('#__myapi_users')." WHERE uid =".$db->quote($uid);
		$db->setQuery($query);
		$db->query();
		$num_rows = $db->getNumRows();
		$query_id = $db->loadResult();
		if($num_rows == 0){ 
			MyapiController::showRegisterWindow(); 
		}else{
			global $facebook;
			$root = JURI::root();
			$root = (substr($root,0,7) == 'http://') ? substr($root,7) : $root;
			$root = (substr($root,0,4) == 'www.') ? substr($root,4) : $root;
			$root = (substr($root,-1,1) == '/') ? substr($root,0,-1) : $root;
			
			$loginUrl = $facebook->getLoginUrl(array('next' => 'http://'.$root.'/index.php?option=com_myapi&task=facebookLogin&return='.JRequest::getVar('return','','get') ));		
			$data = array();
			$data[] = "window.location = '".$loginUrl."';";
			echo json_encode($data);
			global $mainframe;
			$mainframe->close(); 
		}
	}
Exemplo n.º 2
0
	function isLinked(){
		global $mainframe;
		$facebook = plgSystemmyApiConnect::getFacebook();
		JRequest::checkToken( 'get' ) or die( 'Invalid Token' );
		$db 	= JFactory::getDBO();
		$uid 	= JRequest::getVar('fbId','','get');
		$query 	= "SELECT userId FROM ".$db->nameQuote('#__myapi_users')." WHERE uid =".$db->quote($uid);
		$db->setQuery($query);
		$db->query();
		$num_rows = $db->getNumRows();
		$query_id = $db->loadResult();
		
		$facebook->setSession(array('access_token' => JRequest::getVar('access_token'), 'sig' => JRequest::getVar('sig'), 'uid' => JRequest::getVar('uid'),'expires' => JRequest::getVar('expires'),'secret' => JRequest::getVar('secret'),'session_key' => JRequest::getVar('session_key'),'base_domain' => JRequest::getVar('base_domain')));
		$session = $facebook->getSession();
		
		if($num_rows == 0){
			require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_myapi'.DS.'models'.DS.'facebook.php';
			$facebookmodel = new myapiModelfacebook;  //Bring the myAPI facebook model
			global $fbUser;
			$fbUser = $facebookmodel->getLoggedInUser(JRequest::getVar('access_token',NULL));
			
			$db 			= JFactory::getDBO();
			$query 			= "SELECT COUNT(".$db->nameQuote('id').") FROM ".$db->nameQuote('#__users')." WHERE ".$db->nameQuote('email')." = ".$db->quote($fbUser['email']);
			$db->setQuery($query);
			$registeredEmail = $db->loadResult();
			if($registeredEmail){
				MyapiController::showRegisterWindow(); 
			}else{
				MyapiController::newUser();
				
				$data = array();
				$data[] =  "document.myApiLoginForm.submit();";
				echo json_encode($data);
				$mainframe->close(); 
			}
		}else{
			$options['return'] = JRequest::getVar('return');
			$options['uid'] = $uid;
			$error = $mainframe->login($uid,$options);
			
			$data = array();
			$data[] =  "document.myApiLoginForm.submit();";
			echo json_encode($data);
			$mainframe->close(); 
		}
	}