Changeset 31948 in spip-zone
- Timestamp:
- Oct 6, 2009, 2:57:25 AM (11 years ago)
- Location:
- _plugins_/gfc
- Files:
-
- 8 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/gfc/action/gfc_auth.php
r31939 r31948 1 1 <? 2 2 3 /** 4 * Action d'autentification par GFC 5 * 6 * @return 7 */ 8 include_spip('base/abstract_sql'); 3 9 function action_gfc_auth_dist() { 4 10 //ini_set("error_reporting", E_ALL); … … 8 14 //date_default_timezone_set('America/Los_Angeles'); 9 15 16 if(function_exists('lire_config')){ 17 $id = lire_config('gfc/consumer_id') ? lire_config('gfc/consumer_id') : _GFC_CONSUMER_ID; 18 $key = lire_config('gfc/consumer_key') ? lire_config('gfc/consumer_key') : _GFC_CONSUMER_KEY; 19 $secret = lire_config('gfc/consumer_secret') ? str_replace('*:','',lire_config('gfc/consumer_secret')) : str_replace('*:','',_GFC_CONSUMER_SECRET); 20 $default_email = lire_config('gfc/default_email') ? str_replace('*:','',lire_config('gfc/default_email')) : str_replace('*:','',_GFC_DEFAULT_EMAIL); 21 }else{ 22 $id = _GFC_CONSUMER_ID; 23 $secret = _GFC_CONSUMER_SECRET; 24 $default_email = _GFC_DEFAULT_EMAIL; 25 } 26 $token = $_COOKIE['fcauth'.$id]; 27 spip_log("token = $token"); 10 28 //get osapi info 11 29 $display_name = $member_id = false; 12 include_spip(_DIR_OSAPI.'osapi'); 30 include_spip(_DIR_OSAPI."osapi"); 31 //include_spip("auth/osapiSecurityToken"); 32 include_spip("auth/osapiFCAuth"); 13 33 include_spip('inc/texte'); 14 34 include_spip('base/abstract_sql'); 15 35 $provider = new osapiFriendConnectProvider(); 16 $auth = new osapiFCAuth($GLOBALS['gfc']['cookie_value']); 36 //$auth = new osapiOAuth2Legged($key, $secret); 37 $auth = new osapiFCAuth($token); 17 38 $osapi = new osapi($provider, $auth); 18 39 $strictMode = true; 19 40 if ($osapi) { 20 $request = $osapi->people->get(array('userId'=>'@me', 'groupId'=>'@self'));21 41 $batch = $osapi->newBatch(); 22 $batch->add($request, 'me'); 42 //$request = $osapi->people->get($self_request_params), 'self'); 43 $request = $osapi->people->get(array('userId'=>'@viewer', 'groupId'=>'@self')); 44 $batch->add($request, 'self'); 23 45 $result = $batch->execute(); 24 $me = $result['me']; 46 $me = $result['self']; 47 spip_log($result); 25 48 if ($me instanceof osapiError) { 26 49 $code = $me->getErrorCode(); 27 $message = $me->getErrorMessage(); 28 //die("$code - $message");50 $message = $me->getErrorMessage(); 51 die("$code - $message"); 29 52 } 30 53 else{ … … 33 56 if(trim($display_name) == '') $display_name = $member_id; 34 57 } 58 spip_log("member_id = $member_id"); 35 59 } 36 60 //END get osapi info … … 38 62 if($member_id){ 39 63 //try to login SPIP if google friend account already binded 40 if (login_spip($member_id)){} 64 if (login_spip($member_id)){ 65 66 } 41 67 //elseif member already connected in SPIP... 42 else if($GLOBALS['auteur_session']['id_auteur']!=''){68 else if($GLOBALS['visiteur_session']['id_auteur'] !=''){ 43 69 //if he already has a gfc_id, we do nothing !!THIS IS BAD, WE NEED TO WORK ON THIS CASE!! 44 $res = spip_query("select gfc_uid from spip_auteurs where id_auteur=".sql_quote($GLOBALS['auteur_session']['id_auteur'])." and gfc_uid!='' limit 1"); 45 if(sql_count($res)==1){} 70 $id_auteur = sql_getfetsel("id_auteur","spip_auteurs","id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur'])." AND gfc_uid=''"); 46 71 // else we consider this is an attempt to bind a spip account to a google friend account, we automatically bind the 2 account 47 else spip_query("update spip_auteurs set gfc_uid=".sql_quote($member_id)." where id_auteur=".sql_quote($GLOBALS['auteur_session']['id_auteur'])); 72 if($id_auteur){ 73 sql_updateq("spip_auteurs",array('gfc_uid'=> $member_id),"id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur'])); 74 } 48 75 } 49 76 //if not connected to SPIP and gfc_id not in our system, we create a new SPIP account 50 else {77 else if(!sql_getfetsel("id_auteur","spip_auteurs","gfc_uid='$member_id'")){ 51 78 $declaration = array(); 52 $declaration['statut'] = 'nouveau';53 $declaration[' bio'] = 'forum';79 spip_log($_COOKIE['GAUSER']); 80 $declaration['statut'] = '6forum'; 54 81 $declaration['nom'] = safehtml($display_name); 55 $declaration['login'] = $declaration['url_propre'] = ereg_replace("[^a-zA-Z0-9_]", "_", $display_name);;56 $declaration['email'] = $ GLOBALS['gfc']['default_email'];82 $declaration['login'] = preg_replace("[^a-zA-Z0-9_]", "_", $declaration['nom']); 83 $declaration['email'] = $default_email; 57 84 $declaration['gfc_uid'] = $member_id; 58 $n = sql_insert('spip_auteurs', ('(en_ligne,' .join(',',array_keys($declaration)).')'), ("(NOW()," .join(", ",array_map('sql_quote', $declaration)) .")")); 85 $declaration['en_ligne'] = 'NOW()'; 86 $n = sql_insertq('spip_auteurs',$declaration); 59 87 $declaration['id_auteur'] = $n; 60 61 //then we log user in62 login_spip($member_id);63 88 } 89 login_spip($member_id); 64 90 } 65 91 if($_SESSION["gfc"]["login_redirect"] != '') $url_retour = $_SESSION["gfc"]["login_redirect"]; … … 70 96 71 97 function login_spip($gfc_id, $spip_id=''){ 72 if($gfc_id != '') $res = sql_select("*","spip_auteurs","gfc_uid=".sql_quote($gfc_id)." limit 1"); 73 elseif($spip_id != '') $res = spip_query("select * from spip_auteurs where id_auteur=".sql_quote($spip_id)." limit 1"); 74 if ($row = sql_fetch($res)){ 98 if(intval($gfc_id)){ 99 spip_log($gfc_id); 100 $res = sql_select("*","spip_auteurs","gfc_uid='$gfc_id'"); 101 $res = sql_fetch($res); 102 spip_log($res); 103 } 104 elseif($spip_id != '') $res = sql_fetsel("*","spip_auteurs","id_auteur=".sql_quote($spip_id),"","","1"); 105 if ($res){ 106 spip_log($res); 75 107 $auth_source = 'gfc'; 76 $r ow['auth'] = $auth_source;108 $res['auth'] = $auth_source; 77 109 // create session 78 110 $session = charger_fonction('session','inc'); 79 $spip_session = $session($r ow);111 $spip_session = $session($res); 80 112 // create cookie 81 113 $_COOKIE['spip_session'] = $spip_session; … … 83 115 url_de_base(), 84 116 $r); 117 spip_log($r); 85 118 include_spip('inc/cookie'); 86 119 spip_setcookie('spip_session', $spip_session, time() + 3600 * 24 * 14, $r[1]); -
_plugins_/gfc/balise/gfc.php
r31874 r31948 8 8 9 9 function balise_GFC_dyn($param) { 10 if(function_exists('lire_config')){ 11 $key = lire_config('gfc/consumer_id') ? str_replace('*:','',lire_config('gfc/consumer_id')) : str_replace('*:','',_GFC_CONSUMER_ID); 12 $cookie_name = lire_config('gfc/cookie_name') ? lire_config('gfc/cookie_name') : _GFC_COOKIE_NAME; 13 }else{ 14 $key = str_replace('*:','',_GFC_CONSUMER_ID); 15 $cookie_name = _GFC_COOKIE_NAME; 16 } 10 17 switch($param){ 11 18 case "consumer_id": 12 echo $ GLOBALS["gfc"]["consumer_id"];19 echo $key; 13 20 break; 14 21 15 22 case "cookie_name": 16 echo $ GLOBALS["gfc"]["cookie_name"];23 echo $cookie_name; 17 24 break; 18 25 } 19 26 } 20 21 22 23 27 24 28 ?> -
_plugins_/gfc/balise/gfc_login_button.php
r31874 r31948 8 8 9 9 function balise_GFC_LOGIN_BUTTON_dyn($url_retour = '') { 10 if(function_exists('lire_config')){ 11 $cookie_name = lire_config('gfc/cookie_name') ? lire_config('gfc/cookie_name') : _GFC_COOKIE_NAME; 12 }else{ 13 $cookie_name = _GFC_COOKIE_NAME; 14 } 10 15 //don't show button if already logged in, based on the Cookie check 11 if(isset($_COOKIE[$GLOBALS['gfc']['cookie_name']])) return;12 16 13 if($url_retour != '') $_SESSION["gfc"]["login_redirect"] = $url_retour; 14 else $_SESSION["gfc"]["login_redirect"] = self(); 15 //display google friend login template 16 return array('formulaires/gfc_login_button', 0, array( 17 )); 17 if(!isset($_COOKIE[$cookie_name]) OR !isset($GLOBAL['visiteur_session']['id_auteur'])){ 18 if($url_retour != '') $_SESSION["gfc"]["login_redirect"] = $url_retour; 19 else $_SESSION["gfc"]["login_redirect"] = self(); 20 //display google friend login template 21 return array('formulaires/gfc_login_button', 0, array()); 22 } 18 23 } 19 24 -
_plugins_/gfc/gfc_options.php
r31939 r31948 1 1 <?php 2 3 set_include_path(get_include_path() . PATH_SEPARATOR . getcwd().'/'._DIR_PLUGIN_GFC.'auth'); 2 4 3 5 /** … … 5 7 * (telechargee automatiquement ou manuellement a l'installation 6 8 */ 7 define('_DIR_OSAPI',_DIR_RACINE.'lib/opensocial-php-client/osapi/'); 9 define('_DIR_OSAPI','lib/opensocial-php-client/osapi/'); 10 8 11 // USER CONFIG 9 12 10 13 //consumer id 11 $GLOBALS['gfc']['consumer_id'] = '';14 define('_GFC_CONSUMER_ID',''); 12 15 //consumer key 13 $GLOBALS['gfc']['consumer_key'] = '';16 define('_GFC_CONSUMER_KEY',''); 14 17 //consumer secret 15 $GLOBALS['gfc']['consumer_secret'] = '';18 define('_GFC_CONSUMER_SECRET',''); 16 19 //email of members automatically created with this plugin 17 $GLOBALS['gfc']['default_email'] = 'nobody@noone.com';20 define('_GFC_DEFAULT_EMAIL','nobody@noone.com'); 18 21 19 22 //END USER CONFIG 20 21 $GLOBALS['gfc']['cookie_name'] = 'fcauth'.$GLOBALS['gfc']['consumer_id']; 23 define('_GFC_COOKIE_NAME','fcauth'._GFC_CONSUMER_ID); 22 24 $GLOBALS['gfc']['cookie_value'] = $_COOKIE[$GLOBALS['gfc']['cookie_name']]; 23 25 ?> -
_plugins_/gfc/gfc_pipelines.php
r31874 r31948 1 1 <?php 2 2 /** 3 * Insertion dans le pipeline insert_head 4 * 5 * @param array $flux 6 * @return array $flux (le flux modifie) 7 */ 3 8 function gfc_insert_head($flux){ 4 $flux .= "<script src='http://www.google.com/jsapi'></script>"; 9 if(function_exists('lire_config')){ 10 $key = lire_config('gfc/consumer_id') ? lire_config('gfc/consumer_id') : _GFC_CONSUMER_ID; 11 $cookie_name = lire_config('gfc/cookie_name') ? lire_config('gfc/cookie_name') : _GFC_COOKIE_NAME; 12 }else{ 13 $key = _GFC_CONSUMER_ID; 14 } 15 $cookie_name = 'fcauth'.$key; 16 17 $flux .= "<script type='text/javascript' src='http://www.google.com/jsapi'></script>"; 5 18 $flux .= "<script type='text/javascript'>google.load('friendconnect', '0.8');</script>"; 6 19 $flux .= … … 8 21 google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */); 9 22 google.friendconnect.container.initOpenSocialApi({ 10 site: '".$ GLOBALS['gfc']['consumer_id']."',23 site: '".$key."', 11 24 onload: function() { 12 25 if (!window.timesloaded) window.timesloaded = 1; … … 19 32 function gfc_signout(logout_url){ 20 33 //we add this line to manage our login synchronisation, and wether we display the google login button or not 21 document.cookie = 'name=".$ GLOBALS['gfc']['cookie_name'].";path=\"/\";expires=Thu, 01-Jan-1970 00:00:01 GMT;';34 document.cookie = 'name=".$cookie_name.";path=\"/\";expires=Thu, 01-Jan-1970 00:00:01 GMT;'; 22 35 google.friendconnect.requestSignOut(); 23 window.top.location.href = logout_url; 36 if(logout_url){ 37 window.top.location.href = logout_url; 38 } 24 39 }; 25 40 </script>";
Note: See TracChangeset
for help on using the changeset viewer.