-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
164 lines (150 loc) · 3.78 KB
/
login.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
require_once 'Gdata_OAuth_Helper.php';
session_start();
// App Name goes here.
$APP_NAME = 'Gamut';
$APP_URL = getAppURL();
echo $APP_URL;
// Scope defines the services to which access is required.
$scopes = array(
'https://mail.google.com/',
);
// Setup OAuth consumer. Thes values should be replaced with your registered
// app's consumer key/secret.
$CONSUMER_KEY = 'anonymous';
$CONSUMER_SECRET = 'anonymous';
$consumer = new Gdata_OAuth_Helper($CONSUMER_KEY, $CONSUMER_SECRET);
// Main controller logic.
switch (@$_REQUEST['action']) {
case 'logout':
logout($APP_URL);
break;
case 'request_token':
echo 'In Request Token';
$_SESSION['REQUEST_TOKEN'] = serialize($consumer->fetchRequestToken(
implode(' ', $scopes), $APP_URL . '?action=authorize_token'));
echo $_SERVER[ 'ACCESS_TOKEN' ];
echo 'Done Request Token';
$consumer->authorizeRequestToken();
break;
case 'authorize_token':
$consumer->authorizeRequestToken();
break;
case 'access_token':
$_SESSION['ACCESS_TOKEN'] = serialize($consumer->fetchAccessToken());
header('Location: ' . $APP_URL);
break;
default:
if (isset($_SESSION['ACCESS_TOKEN'])) {
$accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
$httpClient = $accessToken->getHttpClient(
$consumer->getOauthOptions());
} else {
renderHTML();
}
}
/**
* Returns a the base URL of the current running web app.
*
* @return string
*/
function getAppURL() {
$pageURL = 'http://';
if ($_SERVER['SERVER_PORT'] != '80') {
$pageURL .= $_SERVER['SERVER_NAME'] . ':' .
$_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'];
} else {
$pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
}
return $pageURL;
}
/**
* Removes session data and redirects the user to a URL.
*
* @param string $redirectUrl The URL to direct the user to after session data
* is destroyed.
* @return void
*/
function logout($redirectUrl) {
session_destroy();
header('Location: ' . $redirectUrl);
exit;
}
/**
* Gets the effective URL based on the availability of token.
*
* @return string
**/
function getRedirectUrl()
{
$redirUrl = $APP_URL;
if (!isset($_SESSION[ 'ACCESS_TOKEN' ])) {
$redirUrl = $redirUrl.'?action=request_token';
}
print $redirUrl;
return $redirUrl;
}
/**
* Prints the token string and secret of the token passed in.
*
* @param Zend_OAuth_Token $token An access or request token object to print.
* @return void
*/
function printToken($token) {
echo '<b>Token:</b>' . $token->getToken() . '<br>';
echo '<b>Token secret:</b>' . $token->getTokenSecret() . '<br>';
}
?>
<?php
function renderHTML() {
?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="default.css" rel="stylesheet" type="text/css">
<title>Gamut...Know your life</title>
</head>
<body>
<table align="center" border="0" height="80%" width="60%"
bgcolor="#77BBFF">
<tbody>
<tr rowspan="2">
<td>
<table align="center" border="0" height="100%" width="100%">
<tbody>
<tr>
<td class="siteTitle">
<dl>
<dd>Gamut.....revisit your past.</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr rowspan="2">
<td colspan="2"></td>
</tr>
<tr>
<td>
<table width=100% height=100% align="center" border="0">
<tbody>
<tr height=100%>
<td width=50%>Gmail account is required to use this site.<br>
</td>
<td width=50%>
<a href="<?php getRedirectUrl();?>">Click Here to Continue</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<?php
}
?>