-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
63 lines (47 loc) · 1.7 KB
/
index.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
<?php
require_once 'public/config/routes.php';
require_once 'vendor/autoload.php';
if (!session_id()) {
session_start();
}
$facebook = new \Facebook\Facebook([
'app_id' => '683401275628249',
'app_secret' => '1d4af98c4c30a7354e12e0c852baefac',
'default_graph_version' => 'v2.10'
]);
$facebook_helper = $facebook->getRedirectLoginHelper();
if (isset($_GET['code'])) {
if (isset($_SESSION['access_token'])) {
$access_token = $_SESSION['access_token'];
} else {
$access_token = $facebook_helper->getAccessToken();
$_SESSION['access_token'] = $access_token;
$facebook->setDefaultAccessToken($_SESSION['access_token']);
}
$_SESSION['user_id'] = '';
$_SESSION['user_name'] = '';
$_SESSION['user_email_address'] = '';
$_SESSION['user_image'] = '';
$graph_response = $facebook->get("/me?fields=name,email", $access_token);
$facebook_user_info = $graph_response->getGraphUser();
if (!empty($facebook_user_info['id'])) {
$_SESSION['user_image'] = 'http://graph.facebook.com/' . $facebook_user_info['id'] . '/picture';
}
if (!empty($facebook_user_info['name'])) {
$_SESSION['user_name'] = $facebook_user_info['name'];
}
if (!empty($facebook_user_info['email'])) {
$_SESSION['user_email_address'] = $facebook_user_info['email'];
}
$_SESSION["id"] = $facebook_user_info['id'];
$_SESSION["loggedin"] = true;
$_SESSION["fullname"] = $facebook_user_info['name'];
$_SESSION["role"] = 1;
header("location: " . ROUTE_HOME);
exit;
}
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
header("location: " . ROUTE_LOGIN);
exit;
}
header("location: " . ROUTE_HOME);