-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.wiki.php
66 lines (60 loc) · 1.75 KB
/
index.wiki.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
<!DOCTYPE html>
<?php
include('config.wiki.php');
$login_button = '';
if(isset($_GET["code"])) {
$token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
if(!isset($token['error'])) {
$google_client->setAccessToken($token['access_token']);
$_SESSION['access_token'] = $token['access_token'];
$google_service = new Google_Service_Oauth2($google_client);
$data = $google_service->userinfo->get();
if (!empty($data['given_name'])) {
$_SESSION['user_first_name'] = $data['given_name'];
}
if (!empty($data['family_name'])) {
$_SESSION['user_last_name'] = $data['family_name'];
}
if (!empty($data['email'])) {
$_SESSION['user_email_address'] = $data['email'];
}
if (!empty($_SESSION['gender'])) {
$_SESSION['user_gender'] = $data['gender'];
}
if (!empty($_SESSION['picture'])) {
$_SESSION['user_image'] = $data['picture'];
}
}
}
if (!isset($_SESSION['access_token'])) {
$login_button = '<a href="'.$google_client->createAuthUrl().'"><img src="img/google-sign-up.png" /></a>';
}
?>
<html>
<head>
<title>wikipoli</title>
</head>
<center><body>
<div class="container">
<br />
<h2 align="centre">PHP Login using google Account</h2>
<br />
<div class="panel panel-default">
<?php
if($login_button == '')
{
echo "<div>Welcome User</div><div>";
echo '<img src="'.$_SESSION["user_image"].'"/>';
echo '<h3><b>Name :</b> '.$_SESSION['user_first_name'].' '.$_SESSION['user_last_name'].'</h3>';
echo '<h3><b>Email :</b> '.$_SESSION['user_email_address'].'</h3>';
echo '<h3><a href="logout.wiki.php">Logout</h3></div>';
}
else
{
echo '<div align="centre">'.$login_button.'</div>';
}
?>
</div>
</div>
</body></center>
</html>