-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb_connector.php
120 lines (108 loc) · 3.78 KB
/
fb_connector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php require_once(dirname(__FILE__) . '/app.php'); ?>
<?php
require 'facebook_conn.php';
$appId = '127413733983248';
$apisecret = 'a9962d08a376a79f8396f3009d9ffca2';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $apisecret,
'cookie' => true,
));
// We may or may not have this data based on a $_GET or $_COOKIE based session.
//
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
// login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
$_SESSION['FB_LOGOUT_URL'] = $logoutUrl;
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* FB.login(function(response) {
Log.info('FB.login callback', response);
if (response.session) {
Log.info('User is logged in');
} else {
Log.info('User is logged out');
}
});
*/
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
//window.open("http://www.facebook.com");
});
};
/*(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
alert(document.getElementById("fb-root"));
document.getElementById("fb-root").appendChild(e);
}());*/
</script>
<?php
// $det = ZLogin::GetLoginId();
if(!$_SESSION['user_id']) {
if($me) {
$login_user = ZUser::GetUserByFB_IdMail($me['id'],$me['email']);
if($login_user) {
if(!$login_user['fb_userid']) {
//update
$sql = "update user set fb_userid = '".$me['id']."',fl_facebook='new' where id ='".$login_user['id']."'";
mysql_query($sql);
//login
Session::Set('user_id', $login_user['id']);
ZLogin::Remember($login_user);
($goto = Session::Get('loginpage', true)) || ($goto = WEB_ROOT.'/index.php');
Utility::Redirect($goto);
} else {
Session::Set('user_id', $login_user['id']);
ZLogin::Remember($login_user);
($goto = Session::Get('loginpage', true)) || ($goto = WEB_ROOT.'/index.php');
Utility::Redirect($goto);
}
} else {
$username = preg_replace("/[^a-z0-9]/i","",strtolower( $me['name']));
$u['email'] = $me['email'];
$u['username'] = $username;
$u['realname'] = $me['first_name']." ".$me['last_name'];
$u['password'] = "fb".rand(1000,2000);
$u['fb_userid'] = $me['id'];
$u['fl_facebook'] = 'new';
$_SESSION['FB_USER_LOGIN'] = $u;
Utility::Redirect( WEB_ROOT . '/account/signupemail.php');
}
}
?>
<fb:login-button onlogin="Groupon.FacebookConnect.onConnect()" perms="publish_stream,email,user_birthday">Connect</fb:login-button>
<!--<fb:login-button></fb:login-button>-->
<?php } ?>