-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfbaccess.php
97 lines (86 loc) · 2.47 KB
/
fbaccess.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
<?php
include_once 'properties.php';
$app_id = $fb_app_id;
$app_secret = $fb_secret_id;
$site_url = $url;
include_once 'vendor/facebook/src/facebook.php';
include_once 'vendor/amazonwebservices/aws-sdk-for-php/sdk.class.php';
session_start();
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$dynamo = new AmazonDynamoDB();
$dynamo->set_hostname("dynamodb.ap-southeast-1.amazonaws.com");
$dynamo->disable_ssl_verification();
date_default_timezone_set('Asia/Kolkata');
$date = date('Y/m/d h:i:s a', time());
$user = $facebook->getUser();
$userNum = intval($user);
if ($user) {
try {
$user_profile = $facebook->api('/me');
}catch(FacebookApiException $e) {
$user=0;
$facebook->destroySession();
}
if (!isset($_SESSION['UserId'])) {
$validUser = false;
if($user) {
try{
// Proceed knowing you have a logged in user who's authenticated.
if ($user_profile != null) {
$response = $dynamo->get_item(array(
"TableName" => "MapPlusPlusUsers",
"Key" => $dynamo->attributes(array(
"HashKeyElement" => $user,
)),
"AttributesToGet" => array("UserId"),
)
);
if ($response->isOK()) {
$item = $response->body->Item;
if (!$item) {
$response_write = $dynamo->put_item(array(
"TableName" => "MapPlusPlusUsers",
"Item" => $dynamo->attributes(array(
"UserId" => $user,
"UserName" => $user_profile['name'],
"email" => $user_profile['email'],
"gender" => $user_profile['gender'],
"CurrentDate" => $date
)
)
));
if ($response_write->isOK()) {
$validUser = true;
}
} elseif(strcmp($user, (string)$item->UserId->{AmazonDynamoDB::TYPE_STRING}) == 0) {
$validUser = true;
} else {
print "Still not a valid user";
}
}
} else {
print "User profile: null";
}
}catch(FacebookApiException $e) {
error_log($e);
$user = NULL;
}
if ($validUser) {
$_SESSION['UserId'] = $user;
$_SESSION['UserProfile'] = $user_profile;
$logoutUrl = $facebook->getLogoutUrl(array(
'next' => $url.$project_path."/logout.php", // URL to which to redirect the user after logging out
));
}
}
} else if ($user) {
$user_profile = $_SESSION['UserProfile'];
$logoutUrl = $facebook->getLogoutUrl(array(
'next' => $url.$project_path."/logout.php", // URL to which to redirect the user after logging out
));
}
}
?>