-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconnect.php
More file actions
66 lines (64 loc) · 2.03 KB
/
connect.php
File metadata and controls
66 lines (64 loc) · 2.03 KB
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
<?php
require_once("system.php");
if(($uid=checklogin())===false){
$E["msg"] = _("no_login");
require("template/login.php");
exit;
}
if(isset($_GET["connect"])){
require("func/facebook-php-sdk-v4/src/Facebook/autoload.php");
$fb = new Facebook\Facebook([
'app_id' => $config['facebook']['app_id'],
'app_secret' => $config['facebook']['app_secret'],
'default_graph_version' => 'v2.5',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
$E["msg"] = _("fb_connect_fail");
require("template/blank.php");
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
$E["msg"] = _("fb_connect_fail");
require("template/blank.php");
exit;
}
if (! isset($accessToken)) {
if ($helper->getError()) {
$E["msg"] = _("fb_connect_fail");
require("template/blank.php");
} else {
$E["msg"] = _("fb_connect_fail");
require("template/blank.php");
}
exit;
}
$response = $fb->get('/me',$accessToken->getValue())->getDecodedBody();
$db = PDO_prepare("SELECT * FROM `table:account` WHERE `fbid` =:fbid");
$db->bindValue("fbid", $response["id"], PDO::PARAM_STR);
$db->execute();
if($db->rowCount()>0){
$E["msg"] = _("fb_already_connect");
require("template/blank.php");
exit;
}
$db = PDO_prepare("UPDATE `table:account` SET `fbid`=:fbid,`fbname`=:fbname WHERE `id`=:uid");
$db->bindValue("fbid", $response["id"], PDO::PARAM_STR);
$db->bindValue("fbname", $response["name"], PDO::PARAM_STR);
$db->bindValue("uid", $uid, PDO::PARAM_STR);
$t=$db->execute();
$E["msg"] = _("fb_connect_ok");
require("template/blank.php");
header('refresh: 3;url=setting.php');
}else if(isset($_GET["disconnect"])){
$db = PDO_prepare("UPDATE `table:account` SET `fbid`='',`fbname`='' WHERE `id`=:uid");
$db->bindValue("uid", $uid, PDO::PARAM_STR);
$db->execute();
$E["msg"] = _("fb_disconnect_ok");
require("template/blank.php");
header('refresh: 3;url=setting.php');
}else {
$E["msg"] = _("fb_connect_fail");
require("template/blank.php");
}