Re: Connexion avec facebook | Titre du sujet : Re: Connexion avec facebook par olivee sur 02/11/2013 21:44:50
il faut tout d’abord créer une application sur facebook mon xoops est 2.5.4
telechargez le module de kraven uploder le dossier lib et preloads dans le module profile créer le fichier connect.php et coller le code dedans en modifiant bien sur Citation :$config = array('appId' => '012345678910', 'secret' => 'jgjhgjgjhgjhgjhgjhgjhgjhgjhgjhghggh' );
<?php
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'header.php';
include dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'mainfile.php';
include dirname(__FILE__) . DIRECTORY_SEPARATOR.'lib'. DIRECTORY_SEPARATOR .'facebook.php';
//$xoops = Xoops::getInstance();
//Connexion à l'application facebook
$config = array('appId' => 'numero de l application FB',
'secret' => 'code sercet donnee par FB'
);
$facebook = new Facebook($config);
//Recupere l'uid facebook de la personne qui se connecte
$currentUser = $facebook->getUser();
//echo $currentUser;
//Lien de Connexion & deconnexion
if ($currentUser) {
//$params = array('next' => XOOPS_URL.'/modules/profile/disconnected.php');
//$params = array('next' => XOOPS_URL . '/user.php?op=logout');
//$logoutUrl = $facebook->getLogoutUrl($params);
//echo('<a href="'.$logoutUrl.'"><img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/4li2k73z.gif">LOGOUT</a>');
//$block['facebook']= '<a href="'.$logoutUrl.'"><img src="/images/fb_logout.png"></a>';
//redirect_header(XOOPS_URL.'/user.php', 1, _US_INCORRECTLOGIN);
} else {
//$params = array('scope' => 'email', 'user_birthday');
//$params = array( 'req_perms' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos,offline_access',
// 'scope' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos,offline_access');
//$loginUrl = $facebook->getLoginUrl($params);
$loginUrl = $facebook->getLoginUrl( array('scope' => 'user_about_me,user_activities,user_birthday,user_checkins,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationships,user_relationship_details,user_religion_politics,user_status,user_videos,user_website,user_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,ads_management,create_event,manage_friendlists,manage_notifications,offline_access,publish_checkins,publish_stream,rsvp_event,sms,publish_actions,manage_pages'));
//echo('<a href="'.$loginUrl.'">facebook</a>');
echo('<a href="'.$loginUrl.'"><img src="http://andylockett.com/wp-content/uploads/2013/02/FacebookButton_post-image.jpg"></a>');
}
//Creation du profil utilisateur
if($currentUser){
try{
$facebook_profile = $facebook->api('/me');
//print_r($facebook_profile);
}
catch (FacebookApiException $e){
setcookie('fbsr_' . $config['appId'], $_COOKIE['fbsr_' . $config['appId']], time() - 3600, "/");
unset($_COOKIE['fbsr_' . $config['appId']]);
// print_r($);
//$currentUser = null;
$currentUser = '';
//$block['facebook']= 'IL faut supprimer les Kookies';
//$block['facebook']= '<a href="/connect.php">Logout</a>';
echo('<a href="/connect.php"><img src="http://andylockett.com/wp-content/uploads/2013/02/FacebookButton_post-image.jpg"></a>');
}
$uid = $facebook_profile['id'];
$username = $facebook_profile['name'];
$name = $facebook_profile['name'];
//$password = $xoops->makePass();
$password = xoops_makepass();
$email = (isset($facebook_profile['email']) && !empty($facebook_profile['email'])) ? $facebook_profile['email'] : $uid . "@".$_SERVER['HTTP_HOST'];
//$email = 'test@facebook.com';
if (!$username || !$email || !$password) {
$adduser_errormsg = _AM_YMCACF;
} else {
//$member_handler1 = $xoops->gethandler('member');
$member_handler1 =& xoops_gethandler('member');
$profile_handler = xoops_getmodulehandler('profile', 'profile');
//Verification de l'existance du membre
if ($member_handler1->getUserCount(new Criteria('uname', $uid)) > 0) {
//Membre present dans la BDD
$uname = trim($uid);
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('email', $email));
$users_arr = $member_handler1->getUsers($criteria);
//var_dump($users_arr);
//if ($users_arr[0]->getVar('uname') == '' || $users_arr[0]->getVar('pass') == '') {
//$xoops->redirect(XOOPS_URL.'/user.php', 1, _US_INCORRECTLOGIN);
//redirect_header(XOOPS_URL.'/user.php', 1, _US_INCORRECTLOGIN);
// exit();
//}
if ($users_arr == false) {
//$xoops->redirect(XOOPS_URL.'/user.php', 1, _US_INCORRECTLOGIN);
redirect_header(XOOPS_URL.'/user.php', 1, _US_INCORRECTLOGIN);
}
if (false != $users_arr) {
if (0 == $users_arr[0]->getVar('level')) {
//$xoops->redirect(XOOPS_URL.'/index.php', 5, _US_NOACTTPADM);
redirect_header(XOOPS_URL.'/index.php', 5, _US_NOACTTPADM);
exit();
}
if ($xoopsConfig['closesite'] == 1) {
$allowed = false;
foreach ($users_arr[0]->getGroups() as $group) {
if (in_array($group, $xoopsConfig['closesite_okgrp']) || XOOPS_GROUP_ADMIN == $group) {
$allowed = true;
break;
}
}
if (!$allowed) {
redirect_header(XOOPS_URL.'/index.php', 1, _NOPERM);
exit();
}
}
$users_arr[0]->setVar('last_login', time());
if (!$member_handler1->insertUser($users_arr[0])) {
}
// Regenerate a new session id and destroy old session
$GLOBALS["sess_handler"]->regenerate_id(true);
$_SESSION = array();
$_SESSION['xoopsUserId'] = $users_arr[0]->getVar('uid');
$_SESSION['xoopsUserGroups'] = $users_arr[0]->getGroups();
$user_theme = $users_arr[0]->getVar('theme');
if (in_array($user_theme, $xoopsConfig['theme_set_allowed'])) {
$_SESSION['xoopsUserTheme'] = $user_theme;
}
// Set cookie for rememberme
//if (!empty($xoopsConfig['usercookie'])) {
//if (!empty($_POST["rememberme"])) {
setcookie($xoopsConfig['usercookie'], $_SESSION['xoopsUserId'] . '-' . md5($users_arr[0]->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX), time() + 31536000, '/', XOOPS_COOKIE_DOMAIN, 0);
//} else {
// setcookie($xoopsConfig['usercookie'], 0, -1, '/', XOOPS_COOKIE_DOMAIN, 0);
//}
//}
if (!empty($_POST['xoops_redirect']) && !strpos($_POST['xoops_redirect'], 'register')) {
$_POST['xoops_redirect'] = trim($_POST['xoops_redirect']);
$parsed = parse_url(XOOPS_URL);
$url = isset($parsed['scheme']) ? $parsed['scheme'].'://' : 'http://';
if (isset( $parsed['host'])) {
$url .= $parsed['host'];
if (isset( $parsed['port'])) {
$url .= ':' . $parsed['port'];
}
} else {
$url .= $_SERVER['HTTP_HOST'];
}
if (@$parsed['path']) {
if (strncmp($parsed['path'], $_POST['xoops_redirect'], strlen( $parsed['path']))) {
$url .= $parsed['path'];
}
}
$url .= $_POST['xoops_redirect'];
} else {
$url = XOOPS_URL . '/index.php';
}
// RMV-NOTIFY
// Perform some maintenance of notification records
$notification_handler =& xoops_gethandler('notification');
$notification_handler->doLoginMaintenance($users_arr[0]->getVar('uid'));
//$xoops->redirect($url, 1, sprintf("", $users_arr[0]->getVar('uname')), false);
//redirect_header($url, 1, sprintf("", $users_arr[0]->getVar('uname')), false);
redirect_header(XOOPS_URL.'/index.php', 5, _US_MERCI_POUR_VOTRE_CONNECTION.' '.$users_arr[0]->getVar('uname'));
} else if (empty($_POST['xoops_redirect'])) {
//$xoops->redirect(XOOPS_URL . '/user.php', 5, '');
redirect_header(XOOPS_URL . '/user.php', 5, '');
} else {
//$xoops->redirect(XOOPS_URL . '/user.php?xoops_redirect=' . urlencode(trim($_POST['xoops_redirect'])), 5, '', false);
redirect_header(XOOPS_URL . '/user.php?xoops_redirect=' . urlencode(trim($_POST['xoops_redirect'])), 5, '', false);
}
} else {
//Creation de l'utilisateur
//$member_handler1 =& xoops_gethandler('member');
$newuser = $member_handler1->createUser();
$profile = $profile_handler->create();
$newuser->setVar("user_viewemail","");
$newuser->setVar("attachsig","");
$newuser->setVar("name", $username);
$newuser->setVar("uname", $uid);
$newuser->setVar("email", $email);
$newuser->setVar("url", "");
//$newuser->setVar("user_avatar",'avatars/'.$currentUser.'.jpg');
$newuser->setVar("user_avatar",'avatars/blank.gif');
$newuser->setVar('user_regdate', time());
$newuser->setVar("user_icq", "");
$newuser->setVar("user_from", "");
$newuser->setVar("user_sig", "");
$newuser->setVar("user_aim", "");
$newuser->setVar("user_yim", "");
$newuser->setVar("user_msnm", "");
$newuser->setVar("pass", md5($password));
$newuser->setVar("timezone_offset", $xoopsConfig['default_TZ']);
$newuser->setVar("uorder", $xoopsConfig['com_order']);
$newuser->setVar("umode",$xoopsConfig['com_mode']);
// RMV-NOTIFY
$newuser->setVar("notify_method", 1);
$newuser->setVar("notify_mode", 1);
$newuser->setVar("bio", "");
$newuser->setVar("rank", 1);
$newuser->setVar("level", 1);
$newuser->setVar("user_occ", "");
$newuser->setVar("user_intrest", "");
$newuser->setVar('user_mailok', true);
if (!$member_handler1->insertUser($newuser, 1)) {
echo $newuser->getHtmlErrors();
echo _AM_NOTINSERTED;
}
$profile->setVar('profile_id', $newuser->getVar('uid') );
$profile_handler->insert($profile);
$newuser1 = $newuser->getVar('uid');
$sqlcommandline = "INSERT INTO " . $xoopsDB -> prefix("groups_users_link") . "(groupid, uid) VALUES ('2', '$newuser1')";
$done = $xoopsDB->queryF($sqlcommandline);
//telecharger le fb_photo
//j'ai supprimé cette partie
//envoyer email de notification
$xoopsMailer =& xoops_getMailer();
$xoopsMailer->useMail();
$mail->setTemplateDir(XOOPS_ROOT_PATH."/modules/profile/language/".$xoopsConfig['language']."/mail_template/");
$xoopsMailer->setTemplate('register.tpl');
$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
$xoopsMailer->assign('SITEURL', XOOPS_URL . "/");
$xoopsMailer->setToUsers($newuser->getVar('uid'));
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
$xoopsMailer->setFromName($xoopsConfig['sitename']);
$xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
$xoopsMailer->send();
if($done) {
redirect_header('index.php', 10, _AM_USERRANK_SAVE);
}
}
}
}
?>
taper http://votresite.com/modules/profile/connect.php
je pense que c'est bien claire mais si vous avez des questions je suis disponible, j'ai supprimé quelques lignes du code que j'utilise parce que c'est codé en vrac.
|
|