This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
/
login.php
174 lines (157 loc) · 4.95 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
165
166
167
168
169
170
171
172
173
174
<?php
$skip_login = true;
session_start();
require_once 'functions.php';
if ($_GET['action'] == "logout") {
$print = _("You have been logged out");
} else {
openid_validate();
}
if (LOCAL) {
$redirect = 'http://ib.is/openstreets/login.php';
$realm = 'http://ib.is/openstreets/';
} else {
$redirect = 'http://friends.openstreets.co.za/login.php';
$realm = 'http://friends.openstreets.co.za/';
}
if ($_GET['state']) {
if ($_GET['state'] != $_SESSION['state']) {
$error = "Invalid session";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.googleapis.com/oauth2/v3/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "code={$_GET['code']}&client_id={$client_id}&client_secret={$client_secret}&redirect_uri={$redirect}&grant_type=authorization_code&openid.realm={$realm}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output);
$info = $output->id_token;
if (!$info) {
$error = "Invalid token";
$error .= "<br />The error returned from Google was: " . $output->error . "<br />" .
$output->error_description;
} else {
require_once 'JWT.php';
$final = JWT::decode($info, $client_secret, false);
$email = $final->email;
if ($final->sub) {
$link_identifier = "accounts.google.com/{$final->sub}";
if (openid_login($link_identifier)) {
header("Location: " . URL . "info/dashboard");
exit();
} elseif ($final->openid_id) {
if (openid_login($final->openid_id, $link_identifier)) {
header("Location: " . URL . "info/dashboard");
exit();
} else {
$error = "User not found.";
}
} else {
$error = "User not found.";
}
} else {
$error = "Invalid response.";
}
}
} else {
$state = md5(rand());
$_SESSION['state'] = $state;
}
?>
<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<head>
<title><?php echo _('Login'); ?> | <?php echo SITENAME ?></title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<style>
.grid .col.six {
width:60%;
}
.grid .col {
float: left;
}
.grid {
margin: 0px auto;
max-width: 1200px;
min-width: 980px;
width: 100%;
}
#wrapper{position:relative;top:120px;}
.btn,.google,.google:hover,.google:active,.google:focus{background:#4285F4}
#openid_choice .btn {
color:#fff;
font-weight:bold;
text-align: center;
line-height:29px;
display:block;
text-shadow:none;
}
#openid_choice i{margin-right:20px;font-size:30px;float:left}
#openid_choice .btn span{position:relative;left:-10px;}
.six {
width:500px;
}
.grid {
min-width:550px;
}
.alert-danger {
padding:10px;
font-weight:bold;
font-size:120%;
color: #A94442;
background-color: #F2DEDE;
border-color: #EBCCD1;
}
#wrapper { font:200 100%/1 Ubuntu,sans-serif }
header {
height: 115px;
width: 100%;
background: url("img/people.png") no-repeat scroll center bottom #333;
position: relative;
box-shadow: 1px 2px 5px 1px #D5D5D5;
}
</style>
</head>
<body class="login">
<header>
<img src="img/logo.png?v=1310" alt="Open Streets">
</header>
<div id="wrapper" class="grid">
<div class="col six center">
<?php if ($error) { ?>
<h2 class="fail">Login Failed</h2>
<p class="alert alert-danger"><strong><?php echo $error ?></strong></p>
<p>
<strong>Be sure to permit cookies
<a href="http://www.google.com/support/accounts/bin/answer.py?&answer=61416">More about cookies</a>.</strong>
</p>
<p><a href="login.php">Try again.</a></p>
<?php } else { ?>
<h2>Login</h2>
<?php if ($print) { echo "<h3 class='notice'>$print</h3>"; } ?>
<form action="" method="get" id="openid_form">
<input type="hidden" name="action" value="verify" />
<input type="hidden" name="login" value="1" />
<fieldset>
<div id="openid_choice">
<p>
<a href="https://accounts.google.com/o/oauth2/auth?client_id=<?php echo $client_id ?>&response_type=code&scope=openid%20email&redirect_uri=<?php echo $redirect ?>&state=<?php echo $state ?>&openid.realm=<?php echo $realm ?>" class="btn btn-large btn-default google">
<i class="fa fa-google"></i>
<span>
Log in with Google
</span>
</a>
</p>
</div>
</fieldset>
</form>
<?php } ?>
</div>
</div>
</body>
</html>